ZQuest Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2025-07-05 10:49:05
Exec Total Coverage
Lines: 1442 5733 25.2%
Functions: 55 110 50.0%
Branches: 610 2915 20.9%

Line Branch Exec Source
1 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
2
3 //glibc 2.28 and later require this: -Z
4 #include <optional>
5 #include <utility>
6 #ifdef __GNUG__
7 #define ALLEGRO_NO_FIX_ALIASES
8 #endif
9
10 #include "base/qrs.h"
11 #include "base/dmap.h"
12 #include "base/zdefs.h"
13 #include "base/zc_alleg.h"
14 #include "zc/script_drawing.h"
15 #include "zc/rendertarget.h"
16 #include "zc/maps.h"
17 #include "tiles.h"
18 #include "zc/zelda.h"
19 #include "zc/ffscript.h"
20 #include "base/util.h"
21 #include "subscr.h"
22 #include "drawing.h"
23 #include "base/mapscr.h"
24 #include "base/misctypes.h"
25 using namespace util;
26 extern refInfo *ri;
27 extern script_bitmaps scb;
28 #include <stdio.h>
29 #include <fstream>
30
31 #define DegtoFix(d) ((d)*0.7111111111111)
32 #define RadtoFix(d) ((d)*40.743665431525)
33
34 static int32_t secondary_draw_origin_xoff;
35 static int32_t secondary_draw_origin_yoff;
36
37 100455706 static std::optional<std::pair<int, int>> get_draw_origin_offset(DrawOrigin draw_origin, int draw_origin_target_uid, int xoff, int yoff)
38 {
39 int xoffset;
40 int yoffset;
41
2/2
✓ Branch 0 taken 40476 times.
✓ Branch 1 taken 100415230 times.
100455706 if (draw_origin == DrawOrigin::Region)
42 {
43 40476 xoffset = xoff - viewport.x;
44 40476 yoffset = yoff - viewport.y;
45 40476 }
46
2/2
✓ Branch 0 taken 8072 times.
✓ Branch 1 taken 100407158 times.
100415230 else if (draw_origin == DrawOrigin::RegionScrollingNew)
47 {
48 8072 xoffset = xoff + FFCore.ScrollingData[SCROLLDATA_NRX];
49 8072 yoffset = yoff + FFCore.ScrollingData[SCROLLDATA_NRY];
50 8072 }
51
2/2
✓ Branch 0 taken 93964676 times.
✓ Branch 1 taken 6442482 times.
100407158 else if (draw_origin == DrawOrigin::PlayingField)
52 {
53 93964676 xoffset = xoff;
54 93964676 yoffset = yoff;
55 93964676 }
56
2/2
✓ Branch 0 taken 6437172 times.
✓ Branch 1 taken 5310 times.
6442482 else if (draw_origin == DrawOrigin::Screen)
57 {
58 6437172 xoffset = 0;
59 6437172 yoffset = 0;
60 6437172 }
61
1/2
✓ Branch 0 taken 5310 times.
✗ Branch 1 not taken.
5310 else if (draw_origin == DrawOrigin::Sprite)
62 {
63 5310 sprite* draw_origin_target = sprite::getByUID(draw_origin_target_uid);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5310 times.
5310 if (!draw_origin_target)
65 {
66 Z_scripterrlog("Warning: Ignoring draw command using DRAW_ORIGIN_SPRITE with non-existent sprite uid: %d.\n", draw_origin_target_uid);
67 return std::nullopt;
68 }
69
70 5310 xoffset = xoff - viewport.x + draw_origin_target->x.getInt();
71 5310 yoffset = yoff - viewport.y + draw_origin_target->y.getInt();
72 5310 }
73 else
74 {
75 // Unexpected.
76 xoffset = 0;
77 yoffset = 0;
78 }
79
80 100455706 return std::make_pair(xoffset, yoffset);
81 100455706 }
82
83 380878 std::pair<int, bool> resolveScriptingBitmapId(int scripting_bitmap_id)
84 {
85
2/2
✓ Branch 0 taken 287889 times.
✓ Branch 1 taken 92989 times.
380878 if (scripting_bitmap_id < 0)
86 {
87 // Handles zscript values for RT_SCREEN, etc.
88 92989 return {scripting_bitmap_id / 10000, false};
89 }
90
3/4
✓ Branch 0 taken 287889 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 780 times.
✓ Branch 3 taken 287109 times.
287889 else if (scripting_bitmap_id - 10 >= -2 && scripting_bitmap_id - 10 <= rtBMP6)
91 {
92 // Handles Game->LoadBitmapID, which sets the bitmap pointer as a "long" int.
93 780 return {scripting_bitmap_id - 10, false};
94 }
95 else
96 {
97 // This is a user bitmap.
98 287109 return {scripting_bitmap_id, true};
99 }
100 380878 }
101
102 static BITMAP* current_target_bmp;
103
104 53694974 static BITMAP* resolveScriptingBitmap(int scripting_bitmap_id)
105 {
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53694974 times.
53694974 if (scripting_bitmap_id < 0)
107 {
108 // Handles zscript values for RT_SCREEN, etc.
109 return FFCore.GetScriptBitmap((scripting_bitmap_id / 10000) + 10, current_target_bmp);
110 }
111 else
112 {
113 // Handles Game->LoadBitmapID, which sets the bitmap pointer as a "long" int.
114 // Also handles user bitmaps.
115 53694974 return FFCore.GetScriptBitmap(scripting_bitmap_id, current_target_bmp);
116 }
117 53694974 }
118
119 inline double sd_log2( double n )
120 {
121 // log(n)/log(2) is log2.
122 double v = log( (double)n ) / log( (double)2 );
123 return v;
124 }
125
126 inline bool isPowerOfTwo(int32_t n)
127 {
128 if(n==0)
129 return false;
130
131 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
132 }
133
134
135
136 template<class T> inline
137 255763 fixed degrees_to_fixed(T d)
138 {
139 255763 return ftofix(DegtoFix(d));
140 }
141 template<class T> inline
142 fixed radians_to_fixed(T d)
143 {
144 return ftofix(RadtoFix(d));
145 }
146
147 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
148
149 class TileHelper
150 {
151 public:
152
153 46094 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
154 {
155 // Past the end of the tile page?
156
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46094 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46094 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
157 {
158 byte w2=(tile+w)%TILES_PER_ROW;
159 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
160 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
161 return;
162 }
163
164
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 46094 times.
46094 switch(flip)
165 {
166 case 1:
167 for(int32_t j=0; j<h; j++)
168 for(int32_t k=w-1; k>=0; k--)
169 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
170
171 break;
172
173 case 2:
174 for(int32_t j=h-1; j>=0; j--)
175 for(int32_t k=0; k<w; k++)
176 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
177
178 break;
179
180 case 3:
181 for(int32_t j=h-1; j>=0; j--)
182 for(int32_t k=w-1; k>=0; k--)
183 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
184
185 break;
186
187 46094 case 0:
188 default:
189
2/2
✓ Branch 0 taken 181240 times.
✓ Branch 1 taken 46094 times.
227334 for(int32_t j=0; j<h; j++)
190
2/2
✓ Branch 0 taken 1111148 times.
✓ Branch 1 taken 181240 times.
1292388 for(int32_t k=0; k<w; k++)
191 1292388 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
192
193 46094 break;
194 }
195 46094 }
196
197 4036845 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
198 {
199 4036845 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
200 4036845 }
201
202 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
203 {
204 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
205 {
206 byte w2=(tile+w)%TILES_PER_ROW;
207 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
208 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
209 return;
210 }
211
212 switch(flip)
213 {
214 case 1:
215 for(int32_t j=0; j<h; j++)
216 for(int32_t k=w-1; k>=0; k--)
217 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
218
219 break;
220
221 case 2:
222 for(int32_t j=h-1; j>=0; j--)
223 for(int32_t k=0; k<w; k++)
224 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
225
226 break;
227
228 case 3:
229 for(int32_t j=h-1; j>=0; j--)
230 for(int32_t k=w-1; k>=0; k--)
231 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
232
233 break;
234
235 default:
236 for(int32_t j=0; j<h; j++)
237 for(int32_t k=0; k<w; k++)
238 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
239
240 break;
241 }
242 }
243
244 288307 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
245 {
246
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 288307 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
288307 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
247 {
248 byte w2=(tile+w)%TILES_PER_ROW;
249 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
250 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
251 return;
252 }
253
254
1/4
✓ Branch 0 taken 288307 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
288307 switch(flip)
255 {
256 case 1:
257 for(int32_t j=0; j<h; j++)
258 for(int32_t k=w-1; k>=0; k--)
259 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
260
261 break;
262
263 case 2:
264 for(int32_t j=h-1; j>=0; j--)
265 for(int32_t k=0; k<w; k++)
266 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
267
268 break;
269
270 case 3:
271 for(int32_t j=h-1; j>=0; j--)
272 for(int32_t k=w-1; k>=0; k--)
273 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
274
275 break;
276
277 default:
278
2/2
✓ Branch 0 taken 1671585 times.
✓ Branch 1 taken 288307 times.
1959892 for(int32_t j=0; j<h; j++)
279
2/2
✓ Branch 0 taken 23550646 times.
✓ Branch 1 taken 1671585 times.
25222231 for(int32_t k=0; k<w; k++)
280 25222231 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
281
282 288307 break;
283 }
284 288307 }
285
286 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
287 {
288 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
289 {
290 byte w2=(tile+w)%TILES_PER_ROW;
291 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
292 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
293 return;
294 }
295
296 switch(flip)
297 {
298 case 1:
299 for(int32_t j=0; j<h; j++)
300 for(int32_t k=w-1; k>=0; k--)
301 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
302
303 break;
304
305 case 2:
306 for(int32_t j=h-1; j>=0; j--)
307 for(int32_t k=0; k<w; k++)
308 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
309
310 break;
311
312 case 3:
313 for(int32_t j=h-1; j>=0; j--)
314 for(int32_t k=w-1; k>=0; k--)
315 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
316
317 break;
318
319 default:
320 for(int32_t j=0; j<h; j++)
321 for(int32_t k=0; k<w; k++)
322 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
323
324 break;
325 }
326 }
327 };
328
329
330
331
332 2499888 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
333 {
334 //sdci[1]=layer
335 //sdci[2]=x
336 //sdci[3]=y
337 //sdci[4]=x2
338 //sdci[5]=y2
339 //sdci[6]=color
340 //sdci[7]=scale factor
341 //sdci[8]=rotation anchor x
342 //sdci[9]=rotation anchor y
343 //sdci[10]=rotation angle
344 //sdci[11]=fill
345 //sdci[12]=opacity
346
1/2
✓ Branch 0 taken 2499888 times.
✗ Branch 1 not taken.
2499888 if(sdci[7]==0) //scale
347 {
348 return;
349 }
350
351 2499888 int32_t x1=sdci[2]/10000;
352 2499888 int32_t y1=sdci[3]/10000;
353 2499888 int32_t x2=sdci[4]/10000;
354 2499888 int32_t y2=sdci[5]/10000;
355
356
1/2
✓ Branch 0 taken 2499888 times.
✗ Branch 1 not taken.
2499888 if(x1>x2)
357 {
358 zc_swap(x1,x2);
359 }
360
361
2/2
✓ Branch 0 taken 2480372 times.
✓ Branch 1 taken 19516 times.
2499888 if(y1>y2)
362 {
363 19516 zc_swap(y1,y2);
364 19516 }
365
366
2/2
✓ Branch 0 taken 2498162 times.
✓ Branch 1 taken 1726 times.
2499888 if(sdci[7] != 10000)
367 {
368 1726 int32_t w=x2-x1+1;
369 1726 int32_t h=y2-y1+1;
370 1726 int32_t w2=(w*sdci[7])/10000;
371 1726 int32_t h2=(h*sdci[7])/10000;
372 1726 x1=x1-((w2-w)/2);
373 1726 x2=x2+((w2-w)/2);
374 1726 y1=y1-((h2-h)/2);
375 1726 y2=y2+((h2-h)/2);
376 1726 }
377
378 2499888 int32_t color=sdci[6]/10000;
379
380
2/2
✓ Branch 0 taken 2463409 times.
✓ Branch 1 taken 36479 times.
2499888 if(sdci[12]/10000<=127) //translucent
381 {
382 36479 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
383 36479 }
384
385
2/2
✓ Branch 0 taken 82060 times.
✓ Branch 1 taken 2417828 times.
2499888 if(sdci[10]==0) //no rotation
386 {
387
2/2
✓ Branch 0 taken 833399 times.
✓ Branch 1 taken 1584429 times.
2417828 if(sdci[11]) //filled
388 {
389 1584429 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
390 1584429 }
391 else //outline
392 {
393 833399 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
394 }
395 2417828 }
396 else //rotate
397 {
398 int32_t xy[16];
399 82060 int32_t rx=sdci[8]/10000;
400 82060 int32_t ry=sdci[9]/10000;
401 82060 fixed ra1=itofix(sdci[10]%10000)/10000;
402 82060 fixed ra2=itofix(sdci[10]/10000);
403 82060 fixed ra=ra1+ra2;
404 82060 ra = (ra/360)*256;
405
406 82060 fixed fcosa = fixcos(ra);
407 82060 fixed fsina = fixsin(ra);
408
409 82060 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
410 82060 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
411 82060 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
412 82060 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
413 82060 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
414 82060 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
415 82060 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
416 82060 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
417 82060 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
418 82060 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
419 82060 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
420 82060 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
421 82060 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
422 82060 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
423 82060 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
424 82060 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
425
426
1/2
✓ Branch 0 taken 82060 times.
✗ Branch 1 not taken.
82060 if(sdci[11]) //filled
427 {
428 82060 polygon(bmp, 4, xy, color);
429 82060 }
430 else //outline
431 {
432 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
433 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
434 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
435 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
436 }
437 }
438
439 2499888 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
440 2499888 }
441
442 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
443 {
444 //sdci[1]=layer
445 //sdci[2]=x
446 //sdci[3]=y
447 //sdci[4]=tile
448 //sdci[5]=cset
449 //sdci[6]=width
450 //sdci[7]=height
451 //sdci[8]=overlay
452 //sdci[9]=opacity
453
454 int32_t x=sdci[2]/10000;
455 int32_t y=sdci[3]/10000;
456
457 int32_t tile=sdci[4]/10000;
458 int32_t cs=sdci[5]/10000;
459 int32_t w=sdci[6]/10000;
460 int32_t h=sdci[7]/10000;
461 bool overlay=sdci[8];
462 bool trans=(sdci[9]/10000<=127);
463
464 frame2x2(bmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
465 }
466
467
468
469 1170321 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
470 {
471 //sdci[1]=layer
472 //sdci[2]=x
473 //sdci[3]=y
474 //sdci[4]=radius
475 //sdci[5]=color
476 //sdci[6]=scale factor
477 //sdci[7]=rotation anchor x
478 //sdci[8]=rotation anchor y
479 //sdci[9]=rotation angle
480 //sdci[10]=fill
481 //sdci[11]=opacity
482
1/2
✓ Branch 0 taken 1170321 times.
✗ Branch 1 not taken.
1170321 if(sdci[6]==0) //scale
483 {
484 return;
485 }
486
487 1170321 int32_t x1=sdci[2]/10000;
488 1170321 int32_t y1=sdci[3]/10000;
489 1170321 qword r=sdci[4];
490
491
1/2
✓ Branch 0 taken 1170321 times.
✗ Branch 1 not taken.
1170321 if(sdci[6] != 10000)
492 {
493 r*=sdci[6];
494 r/=10000;
495 }
496
497 1170321 r/=10000;
498 1170321 int32_t color=sdci[5]/10000;
499
500
2/2
✓ Branch 0 taken 989014 times.
✓ Branch 1 taken 181307 times.
1170321 if(sdci[11]/10000<=127) //translucent
501 {
502 181307 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
503 181307 }
504
505
5/6
✓ Branch 0 taken 58575 times.
✓ Branch 1 taken 1111746 times.
✓ Branch 2 taken 1344 times.
✓ Branch 3 taken 57231 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1344 times.
1170321 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
506 {
507 int32_t xy[2];
508 57231 int32_t rx=sdci[7]/10000;
509 57231 int32_t ry=sdci[8]/10000;
510 57231 fixed ra1=itofix(sdci[9]%10000)/10000;
511 57231 fixed ra2=itofix(sdci[9]/10000);
512 57231 fixed ra=ra1+ra2;
513 57231 ra = (ra/360)*256;
514
515 57231 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
516 57231 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
517 57231 x1=xy[0];
518 57231 y1=xy[1];
519 57231 }
520
521
2/2
✓ Branch 0 taken 1153307 times.
✓ Branch 1 taken 17014 times.
1170321 if(sdci[10]) //filled
522 {
523 1153307 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
524 1153307 }
525 else //outline
526 {
527 17014 circle(bmp, x1+xoffset, y1+yoffset, r, color);
528 }
529
530 1170321 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
531 1170321 }
532
533
534 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
535 {
536 //sdci[1]=layer
537 //sdci[2]=x
538 //sdci[3]=y
539 //sdci[4]=radius
540 //sdci[5]=start angle
541 //sdci[6]=end angle
542 //sdci[7]=color
543 //sdci[8]=scale factor
544 //sdci[9]=rotation anchor x
545 //sdci[10]=rotation anchor y
546 //sdci[11]=rotation angle
547 //sdci[12]=closed
548 //sdci[13]=fill
549 //sdci[14]=opacity
550
551 if(sdci[8]==0) //scale
552 {
553 return;
554 }
555
556 int32_t cx=sdci[2]/10000;
557 int32_t cy=sdci[3]/10000;
558 qword r=sdci[4];
559
560 if(sdci[8] != 10000)
561 {
562 r*=sdci[8];
563 r/=10000;
564 }
565
566 r/=10000;
567
568 int32_t color=sdci[7]/10000;
569
570 fixed ra1=itofix(sdci[11]%10000)/10000;
571 fixed ra2=itofix(sdci[11]/10000);
572 fixed ra=ra1+ra2;
573 ra = (ra/360)*256;
574
575
576 fixed a1=itofix(sdci[5]%10000)/10000;
577 fixed a2=itofix(sdci[5]/10000);
578 fixed sa=a1+a2;
579 sa = (sa/360)*256;
580
581 a1=itofix(sdci[6]%10000)/10000;
582 a2=itofix(sdci[6]/10000);
583 fixed ea=a1+a2;
584 ea = (ea/360)*256;
585
586 if(sdci[11]!=0) //rotation
587 {
588 int32_t rx=sdci[9]/10000;
589 int32_t ry=sdci[10]/10000;
590
591 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
592 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
593 ea-=ra;
594 sa-=ra;
595 }
596
597 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
598 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
599
600 if(sdci[12]) //closed
601 {
602 if(sdci[13]) //filled
603 {
604 clear_bitmap(prim_bmp);
605 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
606 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
607 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
608 int fillx = zc_max(0,fx)+xoffset;
609 int filly = zc_max(0,fy)+yoffset;
610 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
611 floodfill(prim_bmp, fillx, filly, color);
612
613 if(sdci[14]/10000<=127) //translucent
614 {
615 draw_trans_sprite(bmp, prim_bmp, 0,0);
616 }
617 else
618 {
619 draw_sprite(bmp, prim_bmp, 0,0);
620 }
621 }
622 else
623 {
624 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
625 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
626 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
627 }
628 }
629 else
630 {
631 if(sdci[14]/10000<=127) //translucent
632 {
633 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
634 }
635
636 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
637 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
638 }
639 }
640
641
642 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
643 {
644 //sdci[1]=layer
645 //sdci[2]=x
646 //sdci[3]=y
647 //sdci[4]=radiusx
648 //sdci[5]=radiusy
649 //sdci[6]=color
650 //sdci[7]=scale factor
651 //sdci[8]=rotation anchor x
652 //sdci[9]=rotation anchor y
653 //sdci[10]=rotation angle
654 //sdci[11]=fill
655 //sdci[12]=opacity
656
657
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
658 {
659 return;
660 }
661
662 1850 int32_t x1=sdci[2]/10000;
663 1850 int32_t y1=sdci[3]/10000;
664 1850 int32_t radx=sdci[4]/10000;
665 1850 radx*=sdci[7]/10000;
666 1850 int32_t rady=sdci[5]/10000;
667 1850 rady*=sdci[7]/10000;
668 1850 int32_t color=sdci[6]/10000;
669 1850 float rotation = sdci[10]/10000;
670
671 1850 int32_t rx=sdci[8]/10000;
672 1850 int32_t ry=sdci[9]/10000;
673 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
674 1850 fixed ra2=itofix(sdci[10]/10000);
675 1850 fixed ra=ra1+ra2;
676 1850 ra = (ra/360)*256;
677
678 int32_t xy[2];
679 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
680 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
681 1850 x1=xy[0];
682 1850 y1=xy[1];
683
684
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
685
686 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
687
688
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
689 {
690
691
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
692 {
693 1024 clear_bitmap(prim_bmp);
694
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
695 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
696 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
697 1024 }
698 else // no opacity
699 {
700
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
701 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
702 }
703 1630 }
704 else //not filled
705 {
706
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
707 {
708 14 clear_bitmap(prim_bmp);
709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
710 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
711 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
712 14 }
713 else // no opacity
714 {
715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
716 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
717 }
718 }
719
720 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
721 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
722 // the ellipse, but it shouldn't be used anyway.
723
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
724 {
725 // This is very slow, so check the smallest possible square
726 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
727 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
728
729 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
730 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
731 if(getpixel(bmp, x, y)==255)
732 putpixel(bmp, x, y, 0);
733 }
734
735 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
736 1850 }
737
738
739 2351475 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
740 {
741 //sdci[1]=layer
742 //sdci[2]=x
743 //sdci[3]=y
744 //sdci[4]=x2
745 //sdci[5]=y2
746 //sdci[6]=color
747 //sdci[7]=scale factor
748 //sdci[8]=rotation anchor x
749 //sdci[9]=rotation anchor y
750 //sdci[10]=rotation angle
751 //sdci[11]=opacity
752
1/2
✓ Branch 0 taken 2351475 times.
✗ Branch 1 not taken.
2351475 if(sdci[7]==0) //scale
753 {
754 return;
755 }
756
757 2351475 int32_t x1=sdci[2]/10000;
758 2351475 int32_t y1=sdci[3]/10000;
759 2351475 int32_t x2=sdci[4]/10000;
760 2351475 int32_t y2=sdci[5]/10000;
761
762
2/2
✓ Branch 0 taken 1903153 times.
✓ Branch 1 taken 448322 times.
2351475 if(sdci[7] != 10000)
763 {
764 448322 int32_t w=x2-x1+1;
765 448322 int32_t h=y2-y1+1;
766 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
767 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
768 448322 x1=x1-((w2-w)/2);
769 448322 x2=x2+((w2-w)/2);
770 448322 y1=y1-((h2-h)/2);
771 448322 y2=y2+((h2-h)/2);
772 448322 }
773
774 2351475 int32_t color=sdci[6]/10000;
775
776
1/2
✓ Branch 0 taken 2351475 times.
✗ Branch 1 not taken.
2351475 if(sdci[11]/10000<=127) //translucent
777 {
778 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
779 }
780
781
2/2
✓ Branch 0 taken 939459 times.
✓ Branch 1 taken 1412016 times.
2351475 if(sdci[10]!=0) //rotation
782 {
783 int32_t xy[4];
784 1412016 int32_t rx=sdci[8]/10000;
785 1412016 int32_t ry=sdci[9]/10000;
786 1412016 fixed ra1=itofix(sdci[10]%10000)/10000;
787 1412016 fixed ra2=itofix(sdci[10]/10000);
788 1412016 fixed ra=ra1+ra2;
789
790 1412016 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
791 1412016 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
792 1412016 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
793 1412016 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
794 1412016 x1=xy[0];
795 1412016 y1=xy[1];
796 1412016 x2=xy[2];
797 1412016 y2=xy[3];
798 1412016 }
799
800 2351475 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
801 2351475 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
802 2351475 }
803
804 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
805 {
806 //sdci[1]=layer
807 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
808
809 //sdci[2]=x
810 //sdci[3]=y
811 //sdci[4]=x2
812 //sdci[5]=y2
813 //sdci[6]=color
814 //sdci[7]=scale factor
815 //sdci[8]=rotation anchor x
816 //sdci[9]=rotation anchor y
817 //sdci[10]=rotation angle
818 //sdci[11]=opacity
819 //if(sdci[7]==0) //scale
820 //{
821 // return;
822 //}
823
824 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
825
826 if(!v_ptr)
827 {
828 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
829 return;
830 }
831
832 std::vector<int32_t> &v = *v_ptr;
833
834 if(v.empty())
835 return;
836
837 int32_t* pos = &v[0];
838 int32_t sz = v.size();
839
840 for ( int32_t q = 0; q < sz; q+=10 )
841 {
842
843 int32_t x1 = v.at(q);
844 //Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
845 int32_t y1 = v.at(q+1);
846 //Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
847 int32_t x2 = v.at(q+2);
848 //Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
849 int32_t y2 = v.at(q+3);
850 //Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
851 int32_t color = v.at(q+4);
852 //Z_scripterrlog("Lines( colour ) is: %d\n", color);
853 //Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
854 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
855
856 if( v.at(q+5) != 10000)
857 {
858 int32_t w=x2-x1+1;
859 int32_t h=y2-y1+1;
860 int32_t w2=int32_t(w*((double)v.at(q+5)));
861 int32_t h2=int32_t(h*((double)v.at(q+5)));
862 x1=x1-((w2-w)/2);
863 x2=x2+((w2-w)/2);
864 y1=y1-((h2-h)/2);
865 y2=y2+((h2-h)/2);
866 }
867
868
869 //Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
870 if(v.at(q+9) <= 127) //translucent
871 {
872 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
873 }
874 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
875 //Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
876 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
877 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
878 if( v.at(q+8) !=0 ) //rotation
879 {
880 int32_t xy[4];
881
882 int32_t rx = v.at(q+6);
883
884 int32_t ry = v.at(q+7);
885
886 fixed ra1=itofix(v.at(q+8) % 1);
887 fixed ra2=itofix(v.at(q+8));
888 fixed ra=ra1+ra2;
889
890 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
891 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
892 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
893 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
894 x1=xy[0];
895 y1=xy[1];
896 x2=xy[2];
897 y2=xy[3];
898 }
899 //Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
900 //Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
901 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
902 }
903 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
904 }
905
906 1080 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
907 {
908 //sdci[1]=layer
909 //sdci[2]=point count
910 //sdci[3]array[]
911 //sdci[4] = colour
912 //sdci[5] = opacity
913
914 1080 int32_t col = sdci[4]/10000;
915 1080 int32_t op = sdci[5]/10000;
916
917 1080 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
918
919
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(!v_ptr)
920 {
921 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
922 return;
923 }
924
925 1080 std::vector<int32_t> &v = *v_ptr;
926
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if(v.empty())
928 return;
929
930 1080 int32_t* pos = &v[0];
931 1080 int32_t sz = v.size();
932 1080 int32_t numpoints = (sdci[2]/10000);
933
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(sz & 1) --sz; //even amount only
934
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(numpoints > sz/2) //cap to array
935 numpoints = sz/2;
936
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(numpoints < 1)
937 return; //Don't draw 0 or negative point count
938
939
2/2
✓ Branch 0 taken 6480 times.
✓ Branch 1 taken 1080 times.
7560 for (int32_t i = 0; i < sz; i += 2)
940 {
941 6480 pos[i] += xoffset;
942 6480 pos[i + 1] += yoffset;
943 6480 }
944
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if(op <= 127) //translucent
946 {
947 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
948 }
949 1080 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
950
951 1080 polygon(bmp, numpoints, (int32_t*)pos, col);
952 1080 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
953 1080 }
954
955 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
956 {
957 //sdci[1]=layer
958 //sdci[2]=point count
959 //sdci[3]array[]
960 //sdci[4] = colour
961 //sdci[5] = opacity
962
963 int32_t col = sdci[4]/10000;
964 int32_t op = sdci[5]/10000;
965
966 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
967 {
968 Z_scripterrlog("bitmap->Polygon() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
969 return;
970 }
971 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
972 if ( refbmp == NULL ) return;
973
974 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
975
976 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
977
978 if(!v_ptr)
979 {
980 al_trace("bitmap->Polygon: Vector pointer is null! Internal error. \n");
981 return;
982 }
983
984 std::vector<int32_t> &v = *v_ptr;
985
986 if(v.empty())
987 return;
988
989 int32_t* pos = &v[0];
990 int32_t sz = v.size();
991 int32_t numpoints = (sdci[2]/10000);
992 if(sz & 1) --sz; //even amount only
993 if(numpoints > sz/2) //cap to array
994 numpoints = sz/2;
995 if(numpoints < 1)
996 return; //Don't draw 0 or negative point count
997
998 for (int32_t i = 0; i < sz; i += 2)
999 {
1000 pos[i] += xoffset;
1001 pos[i + 1] += yoffset;
1002 }
1003
1004 if(op <= 127) //translucent
1005 {
1006 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1007 }
1008 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1009
1010 polygon(refbmp, numpoints, (int32_t*)pos, col);
1011 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1012 }
1013
1014 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1015 {
1016 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
1017
1018 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
1019 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
1020 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
1021 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
1022 };
1023
1024 if(sdci[11]/10000 < 128) //translucent
1025 {
1026 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1027 }
1028
1029 spline(bmp, points, sdci[10]/10000);
1030
1031 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1032 }
1033
1034
1035 404879 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1036 {
1037 //sdci[1]=layer
1038 //sdci[2]=x
1039 //sdci[3]=y
1040 //sdci[4]=color
1041 //sdci[5]=rotation anchor x
1042 //sdci[6]=rotation anchor y
1043 //sdci[7]=rotation angle
1044 //sdci[8]=opacity
1045 404879 int32_t x1=sdci[2]/10000;
1046 404879 int32_t y1=sdci[3]/10000;
1047 404879 int32_t color=sdci[4]/10000;
1048
1049
2/2
✓ Branch 0 taken 404863 times.
✓ Branch 1 taken 16 times.
404879 if(sdci[8]/10000<=127) //translucent
1050 {
1051 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1052 16 }
1053
1054
1/2
✓ Branch 0 taken 404879 times.
✗ Branch 1 not taken.
404879 if(sdci[7]!=0) //rotation
1055 {
1056 int32_t xy[2];
1057 int32_t rx=sdci[5]/10000;
1058 int32_t ry=sdci[6]/10000;
1059 fixed ra1=itofix(sdci[7]%10000)/10000;
1060 fixed ra2=itofix(sdci[7]/10000);
1061 fixed ra=ra1+ra2;
1062
1063 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1064 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1065 x1=xy[0];
1066 y1=xy[1];
1067 }
1068
1069 404879 putpixel(bmp, x1+xoffset, y1+yoffset, color);
1070 404879 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1071 404879 }
1072
1073 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1074 {
1075 //Z_scripterrlog("Starting putpixels()%s\n");
1076 //sdci[1]=layer
1077 //sdci[2]=array {x,y,colour,opacity}
1078 //sdci[3]=rotation anchor x
1079 //sdci[4]=rotation anchor y
1080 //sdci[5]=rotation angle
1081
1082
1083 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1084
1085 if(!v_ptr)
1086 {
1087 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1088 return;
1089 }
1090
1091 std::vector<int32_t> &v = *v_ptr;
1092
1093 if(v.empty())
1094 return;
1095
1096 int32_t* pos = &v[0];
1097 int32_t sz = v.size();
1098
1099
1100 int32_t x1 = 0;
1101 int32_t y1 = 0;
1102
1103 for ( int32_t q = 0; q < sz; q+=4 )
1104 {
1105 x1 = v.at(q); //pos[q];
1106 y1 = v.at(q+1); //pos[q+1];
1107 if(sdci[5]!=0) //rotation
1108 {
1109 int32_t xy[2];
1110 int32_t rx=sdci[3]/10000;
1111 int32_t ry=sdci[4]/10000;
1112 fixed ra1=itofix(sdci[5]%10000)/10000;
1113 fixed ra2=itofix(sdci[5]/10000);
1114 fixed ra=ra1+ra2;
1115
1116 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1117 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1118 x1=xy[0];
1119 y1=xy[1];
1120 }
1121 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1122 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1123 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1124 }
1125 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1126 }
1127
1128 1576950 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1129 {
1130 //sdci[1]=layer
1131 //sdci[2]=x
1132 //sdci[3]=y
1133 //sdci[4]=tile
1134 //sdci[5]=tile width
1135 //sdci[6]=tile height
1136 //sdci[7]=color (cset)
1137 //sdci[8]=scale x
1138 //sdci[9]=scale y
1139 //sdci[10]=rotation anchor x
1140 //sdci[11]=rotation anchor y
1141 //sdci[12]=rotation angle
1142 //sdci[13]=flip
1143 //sdci[14]=transparency
1144 //sdci[15]=opacity
1145
1146 1576950 int32_t w = sdci[5]/10000;
1147 1576950 int32_t h = sdci[6]/10000;
1148
1149
4/8
✓ Branch 0 taken 1576950 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1576950 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1576950 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1576950 times.
1576950 if(w < 1 || h < 1 || h > 20 || w > 20)
1150 {
1151 return;
1152 }
1153
1154 1576950 int32_t xscale=sdci[8]/10000;
1155 1576950 int32_t yscale=sdci[9]/10000;
1156 1576950 int32_t rx = sdci[10]/10000;
1157 1576950 int32_t ry = sdci[11]/10000;
1158 1576950 float rotation=sdci[12]/10000;
1159 1576950 int32_t flip=(sdci[13]/10000)&3;
1160 1576950 bool transparency=sdci[14]!=0;
1161 1576950 int32_t opacity=sdci[15]/10000;
1162 1576950 int32_t color=sdci[7]/10000;
1163
1164 1576950 int32_t x1=sdci[2]/10000;
1165 1576950 int32_t y1=sdci[3]/10000;
1166
1167 //don't scale if it's not safe to do so
1168 1576950 bool canscale = true;
1169
1170
3/4
✓ Branch 0 taken 1556305 times.
✓ Branch 1 taken 20645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1556305 times.
1576950 if(xscale==0||yscale==0)
1171 {
1172 20645 return;
1173 }
1174
1175
3/4
✓ Branch 0 taken 140477 times.
✓ Branch 1 taken 1415828 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 140477 times.
1556305 if(xscale<=0||yscale<=0)
1176 1415828 canscale = false; //default size
1177
1178
4/4
✓ Branch 0 taken 140477 times.
✓ Branch 1 taken 1415828 times.
✓ Branch 2 taken 140517 times.
✓ Branch 3 taken 1275311 times.
1556305 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1179 {
1180 280994 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1181
1182
1/2
✓ Branch 0 taken 280994 times.
✗ Branch 1 not taken.
280994 if(transparency) //transparency
1183 {
1184 280994 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1185 280994 }
1186 else //no transparency
1187 {
1188 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1189 }
1190
1191
2/2
✓ Branch 0 taken 144205 times.
✓ Branch 1 taken 136789 times.
280994 if(rotation != 0)
1192 {
1193 //low negative values indicate no anchor-point rotation
1194
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 144205 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
144205 if(rx>-777||ry>-777)
1195 {
1196 int32_t xy[2];
1197 144205 fixed ra1=itofix(sdci[12]%10000)/10000;
1198 144205 fixed ra2=itofix(sdci[12]/10000);
1199 144205 fixed ra=ra1+ra2;
1200 144205 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1201 144205 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1202 144205 x1=xy[0];
1203 144205 y1=xy[1];
1204 144205 }
1205
1206
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 140517 times.
144205 if(canscale) //scale first
1207 {
1208 //damnit all, .. fixme.
1209
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1210 3688 clear_bitmap(tempbit);
1211
1212 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1213
1214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1215 {
1216 clear_bitmap(prim_bmp);
1217 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1218 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1219 }
1220 else
1221 {
1222 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1223 }
1224
1225 3688 destroy_bitmap(tempbit);
1226 3688 }
1227 else //no scale
1228 {
1229
2/2
✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 136931 times.
140517 if(opacity < 128)
1230 {
1231 3586 clear_bitmap(prim_bmp);
1232 3586 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1233 3586 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1234 3586 }
1235 else
1236 {
1237 136931 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1238 }
1239 }
1240 144205 }
1241 else //scale only
1242 {
1243
1/2
✓ Branch 0 taken 136789 times.
✗ Branch 1 not taken.
136789 if(canscale)
1244 {
1245
2/2
✓ Branch 0 taken 4344 times.
✓ Branch 1 taken 132445 times.
136789 if(opacity<128)
1246 {
1247 4344 clear_bitmap(prim_bmp);
1248 4344 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1249 4344 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1250 4344 }
1251 else
1252 {
1253 132445 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1254 }
1255 136789 }
1256 else //error -do not scale
1257 {
1258 if(opacity<128)
1259 {
1260 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1261 }
1262 else
1263 {
1264 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1265 }
1266 }
1267 }
1268
1269 280994 script_drawing_commands.ReleaseSubBitmap(pbitty);
1270
1271 280994 }
1272 else // no scale or rotation
1273 {
1274
2/2
✓ Branch 0 taken 1247857 times.
✓ Branch 1 taken 27454 times.
1275311 if(transparency)
1275 {
1276
2/2
✓ Branch 0 taken 224767 times.
✓ Branch 1 taken 1023090 times.
1247857 if(opacity<=127)
1277 224767 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1278 else
1279 1023090 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1280 1247857 }
1281 else
1282 {
1283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27454 times.
27454 if(opacity<=127)
1284 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1285 else
1286 27454 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1287 }
1288 }
1289 1576950 }
1290
1291 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1292 {
1293 //sdci[1]=layer
1294 //sdci[2]=x
1295 //sdci[3]=y
1296 //sdci[4]=tile
1297 //sdci[5]=tile width
1298 //sdci[6]=tile height
1299 //sdci[7]=flip
1300
1301 int32_t w = sdci[5]/10000;
1302 int32_t h = sdci[6]/10000;
1303
1304 if(w < 1 || h < 1 || h > 20 || w > 20)
1305 {
1306 return;
1307 }
1308
1309 int32_t flip=(sdci[7]/10000)&3;
1310
1311 int32_t x1=sdci[2]/10000;
1312 int32_t y1=sdci[3]/10000;
1313
1314 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1315 }
1316
1317
1318 2745108 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1319 {
1320 //sdci[1]=layer
1321 //sdci[2]=x
1322 //sdci[3]=y
1323 //sdci[4]=combo
1324 //sdci[5]=tile width
1325 //sdci[6]=tile height
1326 //sdci[7]=color (cset)
1327 //sdci[8]=scale x
1328 //sdci[9]=scale y
1329 //sdci[10]=rotation anchor x
1330 //sdci[11]=rotation anchor y
1331 //sdci[12]=rotation angle
1332 //sdci[13]=frame
1333 //sdci[14]=flip
1334 //sdci[15]=transparency
1335 //sdci[16]=opacity
1336
1337 2745108 int32_t w = sdci[5]/10000;
1338 2745108 int32_t h = sdci[6]/10000;
1339
1340
4/8
✓ Branch 0 taken 2745108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2745108 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2745108 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2745108 times.
2745108 if(w<1||h<1||h>20||w>20)
1341 {
1342 return;
1343 }
1344 2745108 int32_t cmb = (sdci[4]/10000);
1345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2745108 times.
2745108 if((unsigned)cmb >= MAXCOMBOS)
1346 {
1347 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1348 return;
1349 }
1350
1351 2745108 int32_t xscale=sdci[8]/10000;
1352 2745108 int32_t yscale=sdci[9]/10000;
1353 2745108 int32_t rx = sdci[10]/10000; //these work now
1354 2745108 int32_t ry = sdci[11]/10000; //these work now
1355 2745108 float rotation=sdci[12]/10000;
1356
1357 2745108 bool transparency=sdci[15]!=0;
1358 2745108 int32_t opacity=sdci[16]/10000;
1359 2745108 int32_t color=sdci[7]/10000;
1360 2745108 int32_t x1=sdci[2]/10000;
1361 2745108 int32_t y1=sdci[3]/10000;
1362
1363 2745108 auto& c = GET_DRAWING_COMBO(cmb);
1364 2745108 int32_t tiletodraw = combo_tile(c, x1, y1);
1365 2745108 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1366 2745108 int32_t skiprows=c.skipanimy;
1367
1368
1369 //don't scale if it's not safe to do so
1370 2745108 bool canscale = true;
1371
1372
3/4
✓ Branch 0 taken 2745035 times.
✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2745035 times.
2745108 if(xscale==0||yscale==0)
1373 {
1374 73 return;
1375 }
1376
1377
3/4
✓ Branch 0 taken 23422 times.
✓ Branch 1 taken 2721613 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23422 times.
2745035 if(xscale<=0||yscale<=0)
1378 2721613 canscale = false; //default size
1379
1380
4/4
✓ Branch 0 taken 23422 times.
✓ Branch 1 taken 2721613 times.
✓ Branch 2 taken 102972 times.
✓ Branch 3 taken 2618641 times.
2745035 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1381 {
1382 126394 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1383
1384
2/2
✓ Branch 0 taken 125358 times.
✓ Branch 1 taken 1036 times.
126394 if(transparency)
1385 {
1386 125358 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1387 125358 }
1388 else //no transparency
1389 {
1390 1036 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1391 }
1392
1393
2/2
✓ Branch 0 taken 103190 times.
✓ Branch 1 taken 23204 times.
126394 if(rotation != 0) // rotate
1394 {
1395 //fixed point sucks ;0
1396
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 103190 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
103190 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1397 {
1398 int32_t xy[2];
1399 103190 fixed ra1=itofix(sdci[12]%10000)/10000;
1400 103190 fixed ra2=itofix(sdci[12]/10000);
1401 103190 fixed ra=ra1+ra2;
1402 103190 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1403 103190 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1404 103190 x1=xy[0];
1405 103190 y1=xy[1];
1406 103190 }
1407
1408
2/2
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 102972 times.
103190 if(canscale) //scale first
1409 {
1410
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 218 times.
218 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1411 218 clear_bitmap(tempbit);
1412
1413 218 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1414
1415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if(opacity < 128)
1416 {
1417 clear_bitmap(prim_bmp);
1418 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1419 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1420 }
1421 else
1422 {
1423 218 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1424 }
1425
1426 218 destroy_bitmap(tempbit);
1427 218 }
1428 else //no scale
1429 {
1430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 102972 times.
102972 if(opacity < 128)
1431 {
1432 clear_bitmap(prim_bmp);
1433 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1434 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1435 }
1436 else
1437 {
1438 102972 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1439 }
1440 }
1441 103190 }
1442 else //scale only
1443 {
1444
1/2
✓ Branch 0 taken 23204 times.
✗ Branch 1 not taken.
23204 if(canscale)
1445 {
1446
2/2
✓ Branch 0 taken 9395 times.
✓ Branch 1 taken 13809 times.
23204 if(opacity<128)
1447 {
1448 9395 clear_bitmap(prim_bmp);
1449 9395 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1450 9395 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1451 9395 }
1452 else
1453 {
1454 13809 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1455 }
1456 23204 }
1457 else //error -do not scale
1458 {
1459 if(opacity<128)
1460 {
1461 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1462 }
1463 else
1464 {
1465 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1466 }
1467 }
1468 }
1469
1470 126394 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1471 126394 }
1472 else // no scale or rotation
1473 {
1474
1/2
✓ Branch 0 taken 2618641 times.
✗ Branch 1 not taken.
2618641 if(transparency)
1475 {
1476
2/2
✓ Branch 0 taken 63540 times.
✓ Branch 1 taken 2555101 times.
2618641 if(opacity<=127)
1477 63540 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1478 else
1479 2555101 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1480 2618641 }
1481 else
1482 {
1483 if(opacity<=127)
1484 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1485 else
1486 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1487 }
1488 }
1489 2745108 }
1490
1491 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1492 {
1493 //sdci[1]=layer
1494 //sdci[2]=x
1495 //sdci[3]=y
1496 //sdci[4]=combo
1497 //sdci[5]=tile width
1498 //sdci[6]=tile height
1499 //sdci[7]=flip
1500
1501 int32_t w = sdci[5]/10000;
1502 int32_t h = sdci[6]/10000;
1503
1504 if(w<1||h<1||h>20||w>20)
1505 {
1506 return;
1507 }
1508 int32_t cmb = (sdci[4]/10000);
1509 if((unsigned)cmb >= MAXCOMBOS)
1510 {
1511 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1512 return;
1513 }
1514
1515 int32_t x1=sdci[2]/10000;
1516 int32_t y1=sdci[3]/10000;
1517
1518 auto& c = GET_DRAWING_COMBO(cmb);
1519 int32_t tiletodraw = combo_tile(c, x1, y1);
1520 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1521 int32_t skiprows=c.skipanimy;
1522
1523 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1524 }
1525
1526
1527 5303765 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1528 {
1529 /* layer, x, y, tile, color opacity */
1530
1531 5303765 int32_t opacity = sdci[6]/10000;
1532 5303765 int x = xoffset+(sdci[2]/10000);
1533 5303765 int y = yoffset+(sdci[3]/10000);
1534
1535
2/2
✓ Branch 0 taken 154230 times.
✓ Branch 1 taken 5149535 times.
5303765 if(opacity < 128)
1536 154230 overtiletranslucent16(bmp, sdci[4]/10000, x, y, sdci[5]/10000, 0, opacity);
1537 else
1538 5149535 overtile16(bmp, sdci[4]/10000, x, y, sdci[5]/10000, 0);
1539 5303765 }
1540
1541 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1542 {
1543 /* layer, x, y, tile, color opacity */
1544
1545 //sdci[1]=layer
1546 //sdci[2]=array {x,y,tile,colour,opacity}
1547
1548 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1549
1550 if(!v_ptr)
1551 {
1552 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1553 return;
1554 }
1555
1556 std::vector<int32_t> &v = *v_ptr;
1557
1558 if(v.empty())
1559 return;
1560
1561 int32_t* pos = &v[0];
1562 int32_t sz = v.size();
1563
1564 for ( int32_t q = 0; q < sz; q+=5 )
1565 {
1566
1567 if(v.at(q+4) < 128)
1568 overtiletranslucent16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0, v.at(q+4));
1569 else
1570 overtile16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0);
1571 }
1572 }
1573
1574
1575
1576 22453186 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1577 {
1578 /* layer, x, y, tile, color opacity */
1579
1580 22453186 int32_t opacity = sdci[6] / 10000;
1581 22453186 int32_t x1 = sdci[2] / 10000;
1582 22453186 int32_t y1 = sdci[3] / 10000;
1583
1584 22453186 int32_t cmb = (sdci[4]/10000);
1585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22453186 times.
22453186 if((unsigned)cmb >= MAXCOMBOS)
1586 {
1587 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1588 return;
1589 }
1590
1591 22453186 int x = xoffset+x1;
1592 22453186 int y = yoffset+y1;
1593
1594
2/2
✓ Branch 0 taken 177396 times.
✓ Branch 1 taken 22275790 times.
22453186 if(opacity < 128)
1595 {
1596 177396 overcomboblocktranslucent(bmp, x, y, cmb, sdci[5]/10000, 1, 1, 128);
1597 177396 }
1598 else
1599 {
1600 22275790 overcomboblock(bmp, x, y, cmb, sdci[5]/10000, 1, 1);
1601 }
1602 22453186 }
1603
1604 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1605 {
1606 /* layer, x, y, combo, cset, opacity */
1607 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1608
1609 if(!v_ptr)
1610 {
1611 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1612 return;
1613 }
1614
1615 std::vector<int32_t> &v = *v_ptr;
1616
1617 if(v.empty())
1618 return;
1619
1620 int32_t* pos = &v[0];
1621 int32_t sz = v.size();
1622
1623 for ( int32_t q = 0; q < sz; q+=5 )
1624 {
1625 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1626 {
1627 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1628 continue;
1629 }
1630 if(v.at(q+4) < 128)
1631 {
1632 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1633
1634 }
1635 else
1636 {
1637 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1638 }
1639 }
1640 }
1641
1642
1643
1644
1645 963845 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1646 {
1647 //broken 2.50.2 and earlier drawcharacter()
1648
2/2
✓ Branch 0 taken 18543 times.
✓ Branch 1 taken 945302 times.
963845 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1649 {
1650 //sdci[1]=layer
1651 //sdci[2]=x
1652 //sdci[3]=y
1653 //sdci[4]=font
1654 //sdci[5]=color
1655 //sdci[6]=bg color
1656 //sdci[7]=strech x (width)
1657 //sdci[8]=stretch y (height)
1658 //sdci[9]=char
1659 //sdci[10]=opacity
1660
1661 18543 int32_t x=sdci[2]/10000;
1662 18543 int32_t y=sdci[3]/10000;
1663 18543 int32_t font_index=sdci[4]/10000;
1664 18543 int32_t color=sdci[5]/10000;
1665 18543 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1666 18543 int32_t w=sdci[7]/10000;
1667 18543 int32_t h=sdci[8]/10000;
1668 18543 char glyph=char(sdci[9]/10000);
1669 18543 int32_t opacity=sdci[10]/10000;
1670
1671 //safe check
1672
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(bg_color < -1) bg_color = -1;
1673
1674
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(w>512) w=512; //w=vbound(w,0,512);
1675
1676
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(h>512) h=512; //h=vbound(h,0,512);
1677
1678 //undone
1679
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18543 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18543 if(w>0&&h>0)//stretch the character
1680 {
1681 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1682
1683 if(opacity < 128)
1684 {
1685 if(w>128||h>128)
1686 {
1687 clear_bitmap(prim_bmp);
1688
1689 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1690 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1691 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1692 }
1693 else //this is faster
1694 {
1695 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1696
1697 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1698 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1699 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1700
1701 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1702 }
1703 }
1704 else // no opacity
1705 {
1706 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1707 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1708 }
1709
1710 }
1711 else //no stretch
1712 {
1713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18543 times.
18543 if(opacity < 128)
1714 {
1715 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1716 clear_bitmap(pbmp);
1717
1718 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1719 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1720
1721 destroy_bitmap(pbmp);
1722 }
1723 else // no opacity
1724 {
1725 18543 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1726 }
1727 }
1728 18543 }
1729
1730 else //2.53.0 fixed version and later.
1731 {
1732
1733 //sdci[1]=layer
1734 //sdci[2]=x
1735 //sdci[3]=y
1736 //sdci[4]=font
1737 //sdci[5]=color
1738 //sdci[6]=bg color
1739 //sdci[7]=strech x (width)
1740 //sdci[8]=stretch y (height)
1741 //sdci[9]=char
1742 //sdci[10]=opacity
1743
1744 945302 int32_t x=sdci[2]/10000;
1745 945302 int32_t y=sdci[3]/10000;
1746 945302 int32_t font_index=sdci[4]/10000;
1747 945302 int32_t color=sdci[5]/10000;
1748 945302 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1749 945302 int32_t w=sdci[7]/10000;
1750 945302 int32_t h=sdci[8]/10000;
1751 945302 char glyph=char(sdci[9]/10000);
1752 945302 int32_t opacity=sdci[10]/10000;
1753
1754 //safe check
1755
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(bg_color < -1) bg_color = -1;
1756
1757
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(w>512) w=512; //w=vbound(w,0,512);
1758
1759
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(h>512) h=512; //h=vbound(h,0,512);
1760
1761 //undone
1762
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 945302 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
945302 if(w>0&&h>0)//stretch the character
1763 {
1764 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1765
1766 if(opacity < 128)
1767 {
1768 if(w>128||h>128)
1769 {
1770 clear_bitmap(prim_bmp);
1771
1772 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1773 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1774 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1775 }
1776 else //this is faster
1777 {
1778 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1779
1780 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1781 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1782 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1783
1784 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1785 }
1786 }
1787 else // no opacity
1788 {
1789 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1790 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1791 }
1792
1793 }
1794 else //no stretch
1795 {
1796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 945302 times.
945302 if(opacity < 128)
1797 {
1798 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1799 clear_bitmap(pbmp);
1800
1801 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1802 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1803
1804 destroy_bitmap(pbmp);
1805 }
1806 else // no opacity
1807 {
1808 945302 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1809 }
1810 }
1811
1812 }
1813
1814 963845 }
1815
1816
1817 165084 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1818 {
1819 //broken 2.50.2 and earlier drawinteger()
1820
2/2
✓ Branch 0 taken 72655 times.
✓ Branch 1 taken 92429 times.
165084 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1821 {
1822 //sdci[1]=layer
1823 //sdci[2]=x
1824 //sdci[3]=y
1825 //sdci[4]=font
1826 //sdci[5]=color
1827 //sdci[6]=bg color
1828 //sdci[7]=strech x (width)
1829 //sdci[8]=stretch y (height)
1830 //sdci[9]=integer
1831 //sdci[10]=num decimal places
1832 //sdci[11]=opacity
1833
1834 72655 int32_t x=sdci[2]/10000;
1835 72655 int32_t y=sdci[3]/10000;
1836 72655 int32_t font_index=sdci[4]/10000;
1837 72655 int32_t color=sdci[5]/10000;
1838 72655 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1839 72655 int32_t w=sdci[7]/10000;
1840 72655 int32_t h=sdci[8]/10000;
1841 72655 int32_t decplace=sdci[10]/10000;
1842 72655 int32_t opacity=sdci[11]/10000;
1843
1844 //safe check
1845
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(bg_color < -1) bg_color = -1;
1846
1847
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(w>512) w=512; //w=vbound(w,0,512);
1848
1849
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(h>512) h=512; //h=vbound(h,0,512);
1850
1851 char numbuf[15];
1852
1853
1/6
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72655 switch(decplace)
1854 {
1855 default:
1856 case 0:
1857 72655 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1858 72655 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1859
1860 case 1:
1861 //sprintf(numbuf,"%.01f",number);
1862 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1863 break;
1864
1865 case 2:
1866 //sprintf(numbuf,"%.02f",number);
1867 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1868 break;
1869
1870 case 3:
1871 //sprintf(numbuf,"%.03f",number);
1872 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1873 break;
1874
1875 case 4:
1876 //sprintf(numbuf,"%.04f",number);
1877 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1878 break;
1879 }
1880
1881
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72655 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
72655 if(w>0&&h>0)//stretch
1882 {
1883 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1884
1885 if(opacity < 128)
1886 {
1887 if(w>128||h>128)
1888 {
1889 clear_bitmap(prim_bmp);
1890
1891 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1892 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1893 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1894 }
1895 else
1896 {
1897 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1898 clear_bitmap(pbmp2);
1899
1900 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1901 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1902 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1903
1904 destroy_bitmap(pbmp2);
1905 }
1906 }
1907 else // no opacity
1908 {
1909 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1910 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1911 }
1912
1913 }
1914 else //no stretch
1915 {
1916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72655 times.
72655 if(opacity < 128)
1917 {
1918 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1919 clear_bitmap(pbmp);
1920
1921 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1922 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1923
1924 destroy_bitmap(pbmp);
1925 }
1926 else // no opacity
1927 {
1928 72655 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1929 }
1930 }
1931
1932 72655 }
1933
1934 else //2.53.0 fixed version and later.
1935 {
1936 //sdci[1]=layer
1937 //sdci[2]=x
1938 //sdci[3]=y
1939 //sdci[4]=font
1940 //sdci[5]=color
1941 //sdci[6]=bg color
1942 //sdci[7]=strech x (width)
1943 //sdci[8]=stretch y (height)
1944 //sdci[9]=integer
1945 //sdci[10]=num decimal places
1946 //sdci[11]=opacity
1947
1948 92429 int32_t x=sdci[2]/10000;
1949 92429 int32_t y=sdci[3]/10000;
1950 92429 int32_t font_index=sdci[4]/10000;
1951 92429 int32_t color=sdci[5]/10000;
1952 92429 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1953 92429 int32_t w=sdci[7]/10000;
1954 92429 int32_t h=sdci[8]/10000;
1955 92429 int32_t decplace=sdci[10]/10000;
1956 92429 int32_t opacity=sdci[11]/10000;
1957
1958 //safe check
1959
1/2
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
92429 if(bg_color < -1) bg_color = -1;
1960
1961
1/2
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
92429 if(w>512) w=512; //w=vbound(w,0,512);
1962
1963
1/2
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
92429 if(h>512) h=512; //h=vbound(h,0,512);
1964
1965 char numbuf[15];
1966
1967
1/6
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
92429 switch(decplace)
1968 {
1969 default:
1970 case 0:
1971 92429 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1972 92429 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1973
1974 case 1:
1975 //sprintf(numbuf,"%.01f",number);
1976 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1977 break;
1978
1979 case 2:
1980 //sprintf(numbuf,"%.02f",number);
1981 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1982 break;
1983
1984 case 3:
1985 //sprintf(numbuf,"%.03f",number);
1986 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1987 break;
1988
1989 case 4:
1990 //sprintf(numbuf,"%.04f",number);
1991 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1992 break;
1993 }
1994
1995 //FONT* font=get_zc_font(sdci[4]/10000);
1996
1997
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 92429 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
92429 if(w>0&&h>0)//stretch
1998 {
1999 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
2000 clear_bitmap(pbmp);
2001 //script_drawing_commands.GetSmallTextureBitmap(1,1);
2002
2003 if(opacity < 128)
2004 {
2005 if(w>128||h>128)
2006 {
2007 clear_bitmap(prim_bmp);
2008
2009 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2010 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
2011 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
2012 }
2013 else
2014 {
2015 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
2016 clear_bitmap(pbmp2);
2017
2018 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2019 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
2020 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
2021
2022 destroy_bitmap(pbmp2);
2023 }
2024 }
2025 else // no opacity
2026 {
2027 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2028 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
2029 }
2030
2031 }
2032 else //no stretch
2033 {
2034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92429 times.
92429 if(opacity < 128)
2035 {
2036 FONT* font = get_zc_font(font_index);
2037 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
2038 clear_bitmap(pbmp);
2039
2040 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
2041 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2042
2043 destroy_bitmap(pbmp);
2044 }
2045 else // no opacity
2046 {
2047 92429 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
2048 }
2049 }
2050 }
2051 165084 }
2052
2053
2054 1598985 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2055 {
2056 //sdci[1]=layer
2057 //sdci[2]=x
2058 //sdci[3]=y
2059 //sdci[4]=font
2060 //sdci[5]=color
2061 //sdci[6]=bg color
2062 //sdci[7]=format_option
2063 //sdci[8]=string
2064 //sdci[9]=opacity
2065
2066 1598985 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2067
2068
1/2
✓ Branch 0 taken 1598985 times.
✗ Branch 1 not taken.
1598985 if(!str)
2069 {
2070 al_trace("String pointer is null! Internal error. \n");
2071 return;
2072 }
2073
2074 1598985 int32_t x=sdci[2]/10000;
2075 1598985 int32_t y=sdci[3]/10000;
2076 1598985 FONT* font=get_zc_font(sdci[4]/10000);
2077 1598985 int32_t color=sdci[5]/10000;
2078 1598985 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2079 1598985 int32_t format_type=sdci[7]/10000;
2080 1598985 int32_t opacity=sdci[9]/10000;
2081 //sdci[8] not needed :)
2082
2083 //safe check
2084
1/2
✓ Branch 0 taken 1598985 times.
✗ Branch 1 not taken.
1598985 if(bg_color < -1) bg_color = -1;
2085
2086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1598985 times.
1598985 if(opacity < 128)
2087 {
2088 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2089 if (width < 1) return; //SANITY -Em
2090 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2091 clear_bitmap(pbmp);
2092 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2093 if(format_type == 2) // right-sided text
2094 x-=width;
2095 else if(format_type == 1) // centered text
2096 x-=width/2;
2097 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2098 destroy_bitmap(pbmp);
2099 }
2100 else // no opacity
2101 {
2102
2/2
✓ Branch 0 taken 14345 times.
✓ Branch 1 taken 1584640 times.
1598985 if(format_type == 2) // right-sided text
2103 {
2104 14345 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2105 14345 }
2106
2/2
✓ Branch 0 taken 725712 times.
✓ Branch 1 taken 858928 times.
1584640 else if(format_type == 1) // centered text
2107 {
2108 725712 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2109 725712 }
2110 else // standard left-sided text
2111 {
2112 858928 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2113 }
2114 }
2115 1598985 }
2116
2117 163717 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2118 {
2119 //sdci[1]=layer
2120 //sdci[2]=x
2121 //sdci[3]=y
2122 //sdci[4]=font
2123 //sdci[5]=color
2124 //sdci[6]=bg color
2125 //sdci[7]=format_option
2126 //sdci[8]=string
2127 //sdci[9]=opacity
2128 //sdci[10]=shadowtype
2129 //sdci[11]=shadow_color
2130
2131 163717 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2132
2133
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(!str)
2134 {
2135 al_trace("String pointer is null! Internal error. \n");
2136 return;
2137 }
2138
2139 163717 int32_t x=sdci[2]/10000;
2140 163717 int32_t y=sdci[3]/10000;
2141 163717 FONT* font=get_zc_font(sdci[4]/10000);
2142 163717 int32_t color=sdci[5]/10000;
2143 163717 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2144 163717 int32_t format_type=sdci[7]/10000;
2145 163717 int32_t opacity=sdci[9]/10000;
2146 163717 int32_t textstyle = sdci[10]/10000;
2147 163717 int32_t shadow_color = sdci[11]/10000;
2148 //sdci[8] not needed :)
2149
2150 //safe check
2151
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(bg_color < -1) bg_color = -1;
2152
2153
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 162977 times.
163717 if(opacity < 128)
2154 {
2155
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2156
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2157 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2158 740 clear_bitmap(pbmp);
2159 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2160 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2162 x-=width;
2163
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2164 740 x-=width/2;
2165 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2166 740 destroy_bitmap(pbmp);
2167 740 }
2168 else // no opacity
2169 {
2170 162977 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2171 }
2172 163717 }
2173
2174
2175 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2176 {
2177 //sdci[1]=layer
2178 //sdci[2]=x1
2179 //sdci[3]=y1
2180 //sdci[4]=x2
2181 //sdci[5]=y2
2182 //sdci[6]=x3
2183 //sdci[7]=y3
2184 //sdci[8]=x4
2185 //sdci[9]=y4
2186 //sdci[10]=width
2187 //sdci[11]=height
2188 //sdci[12]=cset
2189 //sdci[13]=flip
2190 //sdci[14]=tile/combo
2191 //sdci[15]=polytype
2192
2193 9266 int32_t x1 = sdci[2]/10000;
2194 9266 int32_t y1 = sdci[3]/10000;
2195 9266 int32_t x2 = sdci[4]/10000;
2196 9266 int32_t y2 = sdci[5]/10000;
2197 9266 int32_t x3 = sdci[6]/10000;
2198 9266 int32_t y3 = sdci[7]/10000;
2199 9266 int32_t x4 = sdci[8]/10000;
2200 9266 int32_t y4 = sdci[9]/10000;
2201 9266 int32_t w = sdci[10]/10000;
2202 9266 int32_t h = sdci[11]/10000;
2203 9266 int32_t color = sdci[12]/10000;
2204 9266 int32_t flip=(sdci[13]/10000)&3;
2205 9266 int32_t tile = sdci[14]/10000;
2206 9266 int32_t polytype = sdci[15]/10000;
2207
2208 //todo: finish palette shading
2209 /*
2210 POLYTYPE_FLAT
2211 POLYTYPE_GCOL
2212 POLYTYPE_GRGB
2213 POLYTYPE_ATEX
2214 POLYTYPE_PTEX
2215 POLYTYPE_ATEX_MASK
2216 POLYTYPE_PTEX_MASK
2217 POLYTYPE_ATEX_LIT
2218 POLYTYPE_PTEX_LIT
2219 POLYTYPE_ATEX_MASK_LIT
2220 POLYTYPE_PTEX_MASK_LIT
2221 POLYTYPE_ATEX_TRANS
2222 POLYTYPE_PTEX_TRANS
2223 POLYTYPE_ATEX_MASK_TRANS
2224 POLYTYPE_PTEX_MASK_TRANS
2225 */
2226 9266 polytype = vbound(polytype, 0, 14);
2227
2228
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2229 {
2230 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2231 return; //non power of two error
2232 }
2233
2234 9266 int32_t tex_width = w*16;
2235 9266 int32_t tex_height = h*16;
2236
2237 BITMAP *tex;
2238
2239 9266 bool mustDestroyBmp = false;
2240
2241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2242 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2243
2244
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(!tex)
2245 {
2246 mustDestroyBmp = true;
2247 tex = create_bitmap_ex(8, tex_width, tex_height);
2248 clear_bitmap(tex);
2249 }
2250
2251 int32_t col[4];
2252 /*
2253 if( color < 0 )
2254 {
2255 col[0]=draw_container.color_buffer[0];
2256 col[1]=draw_container.color_buffer[1];
2257 col[2]=draw_container.color_buffer[2];
2258 col[3]=draw_container.color_buffer[3];
2259 }
2260 else */
2261 {
2262 9266 col[0]=col[1]=col[2]=col[3]=color;
2263 }
2264
2265
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2266 {
2267 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2268 }
2269
2270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile < 0 ) // COMBO
2271 {
2272 9266 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
2273 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2274 9266 flip = flip ^ c.flip;
2275
2276 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2277 9266 }
2278
2279 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2280 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2281 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2282 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2283
2284 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2285
2286
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2287 destroy_bitmap(tex);
2288
2289 9266 }
2290
2291
2292 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2293 {
2294 //sdci[1]=layer
2295 //sdci[2]=x1
2296 //sdci[3]=y1
2297 //sdci[4]=x2
2298 //sdci[5]=y2
2299 //sdci[6]=x3
2300 //sdci[7]=y3
2301 //sdci[8]=width
2302 //sdci[9]=height
2303 //sdci[10]=cset
2304 //sdci[11]=flip
2305 //sdci[12]=tile/combo
2306 //sdci[13]=polytype
2307
2308 int32_t x1 = sdci[2]/10000;
2309 int32_t y1 = sdci[3]/10000;
2310 int32_t x2 = sdci[4]/10000;
2311 int32_t y2 = sdci[5]/10000;
2312 int32_t x3 = sdci[6]/10000;
2313 int32_t y3 = sdci[7]/10000;
2314 int32_t w = sdci[8]/10000;
2315 int32_t h = sdci[9]/10000;
2316 int32_t color = sdci[10]/10000;
2317 int32_t flip=(sdci[11]/10000)&3;
2318 int32_t tile = sdci[12]/10000;
2319 int32_t polytype = sdci[13]/10000;
2320
2321 polytype = vbound(polytype, 0, 14);
2322
2323 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2324 {
2325 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2326 return; //non power of two error
2327 }
2328
2329 int32_t tex_width = w*16;
2330 int32_t tex_height = h*16;
2331
2332 bool mustDestroyBmp = false;
2333 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2334
2335 if(!tex)
2336 {
2337 mustDestroyBmp = true;
2338 tex = create_bitmap_ex(8, tex_width, tex_height);
2339 clear_bitmap(tex);
2340 }
2341
2342 int32_t col[3];
2343 /*
2344 if( color < 0 )
2345 {
2346 col[0]=draw_container.color_buffer[0];
2347 col[1]=draw_container.color_buffer[1];
2348 col[2]=draw_container.color_buffer[2];
2349 }
2350 else */
2351 {
2352 col[0]=col[1]=col[2]=color;
2353 }
2354
2355 if(tile > 0) // TILE
2356 {
2357 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2358 }
2359 else // COMBO
2360 {
2361 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
2362 const int32_t tiletodraw = combo_tile(c, x1, y1);
2363 flip = flip ^ c.flip;
2364
2365 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2366 }
2367
2368 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2369 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2370 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2371
2372
2373 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2374
2375 if(mustDestroyBmp)
2376 destroy_bitmap(tex);
2377 }
2378
2379
2380 933060 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2381 {
2382 //sdci[1]=layer
2383 //sdci[2]=bitmap
2384 //sdci[3]=sourcex
2385 //sdci[4]=sourcey
2386 //sdci[5]=sourcew
2387 //sdci[6]=sourceh
2388 //sdci[7]=destx
2389 //sdci[8]=desty
2390 //sdci[9]=destw
2391 //sdci[10]=desth
2392 //sdci[11]=rotation
2393 //sdci[12]=mask
2394
2395 933060 int32_t bitmapIndex = sdci[2]/10000;
2396 933060 int32_t sx = sdci[3]/10000;
2397 933060 int32_t sy = sdci[4]/10000;
2398 933060 int32_t sw = sdci[5]/10000;
2399 933060 int32_t sh = sdci[6]/10000;
2400 933060 int32_t dx = sdci[7]/10000;
2401 933060 int32_t dy = sdci[8]/10000;
2402 933060 int32_t dw = sdci[9]/10000;
2403 933060 int32_t dh = sdci[10]/10000;
2404 933060 float rot = sdci[11]/10000;
2405 933060 bool masked = (sdci[12] != 0);
2406
2407 //bugfix
2408 933060 sx = vbound(sx, 0, 512);
2409 933060 sy = vbound(sy, 0, 512);
2410 933060 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2411 933060 sh = vbound(sh, 0, 512 - sy);
2412
2413
2414
2/4
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 933060 times.
933060 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2415 return;
2416
2417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 933060 times.
933060 bool stretched = (sw != dw || sh != dh);
2418
2419 933060 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2420
2421
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(!sourceBitmap)
2422 {
2423 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2424 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2425 return;
2426 }
2427
2428 933060 BITMAP* subBmp = 0;
2429
2430
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(rot != 0)
2431 {
2432 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2433
2434 if(!subBmp)
2435 {
2436 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2437 return;
2438 }
2439 }
2440
2441
2442 933060 dx = dx + xoffset;
2443 933060 dy = dy + yoffset;
2444
2445
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 932820 times.
933060 if(stretched)
2446 {
2447
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2448 {
2449
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2450 {
2451 //if ( rot == 4096 ) { //translucent
2452 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2453 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2454 // draw_trans_sprite(bmp, subBmp, dx, dy);
2455 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2456
2457
2458 // }
2459 //else {
2460 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2461 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2462 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2463 //
2464
2465 // }
2466 }
2467 else
2468 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2469 240 }
2470 else
2471 {
2472 if(rot != 0)
2473 {
2474 //if ( rot == 4096 ) { //translucent
2475 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2476 // draw_trans_sprite(bmp, subBmp, dx, dy);
2477 // }
2478 //else {
2479 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2480 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2481 // }
2482 }
2483 else
2484 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2485 }
2486 240 }
2487 else
2488 {
2489
2/2
✓ Branch 0 taken 928098 times.
✓ Branch 1 taken 4722 times.
932820 if(masked)
2490 {
2491
1/2
✓ Branch 0 taken 928098 times.
✗ Branch 1 not taken.
928098 if(rot != 0)
2492 {
2493 //if ( rot == 4096 ) {//translucent
2494 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2495 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2496
2497 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2498 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2499 // draw_trans_sprite(bmp, subBmp, dx, dy);
2500 // }
2501 //else {
2502 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2503 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2504 // }
2505 }
2506 else
2507 928098 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2508 928098 }
2509 else
2510 {
2511
1/2
✓ Branch 0 taken 4722 times.
✗ Branch 1 not taken.
4722 if(rot != 0)
2512 {
2513 //if ( rot == 4096 ) { //translucent
2514 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2515 // draw_trans_sprite(bmp, subBmp, dx, dy);
2516 // }
2517 //else {
2518 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2519 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2520 // }
2521 }
2522 else
2523 4722 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2524 }
2525 }
2526
2527 //cleanup
2528
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(subBmp)
2529 {
2530 script_drawing_commands.ReleaseSubBitmap(subBmp);
2531 }
2532 933060 }
2533
2534
2535 //Draw]()
2536 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2537 {
2538 /*
2539 //sdci[1]=layer
2540 //sdci[2]=bitmap
2541 //sdci[3]=sourcex
2542 //sdci[4]=sourcey
2543 //sdci[5]=sourcew
2544 //sdci[6]=sourceh
2545 //sdci[7]=destx
2546 //sdci[8]=desty
2547 //sdci[9]=destw
2548 //sdci[10]=desth
2549 //sdci[11]=rotation/angle
2550 //scdi[12] = pivot cx
2551 //sdci[13] = pivot cy
2552 //scdi[14] = effect flags
2553
2554
2555 const int32_t BITDX_NORMAL = 0;
2556 const int32_t BITDX_TRANS = 1; //Translucent
2557 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2558 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2559 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2560 //Note: Some modes cannot be combined. if a combination is not supported, an error
2561 // detailing this will be shown in allegro.log.
2562
2563 //scdi[15] = litcolour
2564 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2565 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2566
2567 //sdci[16]=mask
2568
2569 */
2570
2571 int32_t bitmapIndex = sdci[2]/10000;
2572 int32_t sx = sdci[3]/10000;
2573 int32_t sy = sdci[4]/10000;
2574 int32_t sw = sdci[5]/10000;
2575 int32_t sh = sdci[6]/10000;
2576 int32_t dx = sdci[7]/10000;
2577 int32_t dy = sdci[8]/10000;
2578 int32_t dw = sdci[9]/10000;
2579 int32_t dh = sdci[10]/10000;
2580 float rot = sdci[11]/10000;
2581 int32_t cx = sdci[12]/10000;
2582 int32_t cy = sdci[13]/10000;
2583 int32_t mode = sdci[14]/10000;
2584 int32_t litcolour = sdci[15]/10000;
2585 bool masked = (sdci[16] != 0);
2586
2587
2588
2589 //bugfix
2590 sx = vbound(sx, 0, 512);
2591 sy = vbound(sy, 0, 512);
2592 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2593 sh = vbound(sh, 0, 512 - sy);
2594
2595
2596 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2597 return;
2598
2599 bool stretched = (sw != dw || sh != dh);
2600
2601 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2602
2603 if(!sourceBitmap)
2604 {
2605 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2606 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2607 return;
2608 }
2609
2610 BITMAP* subBmp = 0;
2611
2612 /*
2613 if ( bitmapIndex == -1 ) {
2614 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2615 }
2616 */
2617
2618 if(rot != 0 || mode != 0)
2619 {
2620 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2621
2622 if(!subBmp)
2623 {
2624 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2625 return;
2626 }
2627 }
2628
2629
2630 dx = dx + xoffset;
2631 dy = dy + yoffset;
2632
2633 if(stretched)
2634 {
2635 if(masked) //stretched and masked
2636 {
2637 if ( rot == 0 ) //if not rotated
2638 {
2639 switch(mode)
2640 {
2641 case 1:
2642 //transparent
2643 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2644 draw_trans_sprite(bmp, subBmp, dx, dy);
2645 break;
2646
2647
2648 case 2:
2649 //pivot?
2650 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2651 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2652 //Pivoting requires two more args
2653 break;
2654
2655 case 3:
2656 //pivot + trans
2657 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2658 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2659 break;
2660
2661 case 4:
2662 //flip v
2663 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2664 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2665 break;
2666
2667 case 5:
2668 //trans + v flip
2669 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2670 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2671 break;
2672
2673 case 6:
2674 //pivot + v flip
2675 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2676 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2677 break;
2678
2679 case 8:
2680 //vlip h
2681 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2682 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2683 break;
2684
2685 case 9:
2686 //trans + h flip
2687 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2688 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2689 break;
2690
2691 case 10:
2692 //flip H and pivot
2693 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2694 //return error cannot pivot and h flip
2695 break;
2696
2697 case 12:
2698 //vh flip
2699 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2700 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2701 break;
2702
2703 case 13:
2704 //trans + vh flip
2705 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2706 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2707 break;
2708
2709 case 14:
2710 //pivot and vh flip
2711 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2712 //return error cannot both pivot and vh flip
2713 break;
2714
2715 case 16:
2716 //lit
2717 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2718 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2719 break;
2720
2721 case 18:
2722 //pivot, lit
2723 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2724 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2725 break;
2726
2727 case 20:
2728 //lit + v flip
2729 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2730 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2731 break;
2732
2733 case 22:
2734 //Pivot, vflip, lit
2735 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2736 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2737 break;
2738
2739 case 24:
2740 //lit + h flip
2741 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2742 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2743 break;
2744
2745 case 26:
2746 //pivot + lit + hflip
2747 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2748 //return error cannot pivot, lit, and flip
2749 break;
2750
2751 case 28:
2752 //lit + vh flip
2753 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2754 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2755 break;
2756
2757 case 32: //gouraud
2758 //Probably not wort supporting.
2759 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2760 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2761 break;
2762
2763 case 0:
2764 //no effect
2765 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2766 break;
2767
2768
2769 default:
2770 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2771
2772
2773 }
2774 } //end if not rotated
2775
2776 if ( rot != 0 ) //if rotated
2777 {
2778 switch(mode)
2779 {
2780 case 1:
2781 //transparent
2782 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2783 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2784
2785 break;
2786
2787 case 2:
2788 //pivot?
2789 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2790 //return an error, cannot both rotate and pivot
2791 break;
2792
2793 case 3:
2794 //pivot + trans
2795 //return an error, cannot both rotate and pivot
2796 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2797 break;
2798
2799 case 4:
2800 //flip v
2801 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2802 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2803 break;
2804
2805 case 5:
2806 //trans + v flip
2807 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2808 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2809 break;
2810
2811 case 6:
2812 //pivot + v flip
2813 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2814 //return an error, cannot both rotate and pivot
2815 break;
2816
2817 case 8:
2818 //flip h
2819 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2820 //return an error, cannot both rotate and flip H
2821 break;
2822
2823 case 9:
2824 //trans + h flip
2825 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2826 //return an error, cannot rotate and flip a trans sprite
2827 break;
2828
2829 case 10:
2830 //flip H and pivot
2831 //return error cannot pivot and h flip
2832 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2833 break;
2834
2835 case 12:
2836 //vh flip
2837 //return an error, cannot rotate and VH flip a trans sprite
2838 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2839 break;
2840
2841 case 13:
2842 //trans + vh flip
2843 //return an error, cannot rotate and VH flip a trans sprite
2844 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2845 break;
2846
2847 case 14:
2848 //pivot and vh flip
2849 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2850 //return error cannot both pivot and vh flip
2851 break;
2852
2853 case 16:
2854 //lit
2855 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2856 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2857 break;
2858
2859 case 18:
2860 //pivot, lit
2861 //return an error, cannot both rotate and pivot
2862 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2863 break;
2864
2865 case 20:
2866 //lit + vflip
2867 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2868 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2869 break;
2870
2871 case 22:
2872 //Pivot, vflip, lit
2873 //return an error, cannot both rotate and pivot
2874 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2875 break;
2876
2877 case 24:
2878 //lit + h flip
2879 //return an error, cannot both rotate and H flip
2880 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2881 break;
2882
2883 case 26:
2884 //pivot + lit + hflip
2885 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2886 //return error cannot pivot, lit, and flip
2887 break;
2888
2889 case 28:
2890 //lit + vh flip
2891 //return an error, cannot both rotate and VH flip
2892 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2893 break;
2894
2895 case 32: //gouraud
2896 //Probably not wort supporting.
2897 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2898 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2899 break;
2900
2901 case 0:
2902 //no effect.
2903 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2904 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2905 break;
2906
2907 default:
2908 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2909
2910 }
2911 }
2912 } //end if stretched and masked
2913
2914 else //stretched, not masked
2915 {
2916 if ( rot == 0 ) //if not rotated
2917 {
2918 switch(mode) {
2919 case 1:
2920 //transparent
2921 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2922 draw_trans_sprite(bmp, subBmp, dx, dy);
2923 break;
2924
2925
2926 case 2:
2927 //pivot?
2928 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2929 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2930 //Pivoting requires two more args
2931 break;
2932
2933 case 3:
2934 //pivot + trans
2935 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2936 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2937 break;
2938
2939 case 4:
2940 //flip v
2941 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2942 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2943 break;
2944
2945 case 5:
2946 //trans + v flip
2947 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2948 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2949 break;
2950
2951 case 6:
2952 //pivot + v flip
2953 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2954 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2955 break;
2956
2957 case 8:
2958 //vlip h
2959 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2960 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2961 break;
2962
2963 case 9:
2964 //trans + h flip
2965 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2966 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2967 break;
2968
2969 case 10:
2970 //flip H and pivot
2971 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2972 //return error cannot pivot and h flip
2973 break;
2974
2975 case 12:
2976 //vh flip
2977 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2978 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2979 break;
2980
2981 case 13:
2982 //trans + vh flip
2983 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2984 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2985 break;
2986
2987 case 14:
2988 //pivot and vh flip
2989 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2990 //return error cannot both pivot and vh flip
2991 break;
2992
2993 case 16:
2994 //lit
2995 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2996 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2997 break;
2998
2999 case 18:
3000 //pivot, lit
3001 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3002 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3003 break;
3004
3005 case 20:
3006 //lit + v flip
3007 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3008 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3009 break;
3010
3011 case 22:
3012 //Pivot, vflip, lit
3013 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3014 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3015 break;
3016
3017 case 24:
3018 //lit + h flip
3019 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3020 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3021 break;
3022
3023 case 26:
3024 //pivot + lit + hflip
3025 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3026 //return error cannot pivot, lit, and flip
3027 break;
3028
3029 case 28:
3030 //lit + vh flip
3031 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3032 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3033 break;
3034
3035 case 32: //gouraud
3036 //Probably not wort supporting.
3037 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3038 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3039 break;
3040
3041 case 0:
3042 //no effect
3043 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
3044 break;
3045
3046
3047 default:
3048 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3049
3050
3051 }
3052 } //end if not rotated
3053
3054 if ( rot != 0 ) //if rotated
3055 {
3056 switch(mode)
3057 {
3058 case 1:
3059 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3060 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3061
3062 break;
3063
3064 case 2:
3065 //pivot?
3066 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3067 //return an error, cannot both rotate and pivot
3068 break;
3069
3070 case 3:
3071 //pivot + trans
3072 //return an error, cannot both rotate and pivot
3073 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3074 break;
3075
3076 case 4:
3077 //flip v
3078 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3079 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3080 break;
3081
3082 case 5:
3083 //trans + v flip
3084 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3085 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3086 break;
3087
3088 case 6:
3089 //pivot + v flip
3090 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3091 //return an error, cannot both rotate and pivot
3092 break;
3093
3094 case 8:
3095 //flip h
3096 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3097 //return an error, cannot both rotate and flip H
3098 break;
3099
3100 case 9:
3101 //trans + h flip
3102 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3103 //return an error, cannot rotate and flip a trans sprite
3104 break;
3105
3106 case 10:
3107 //flip H and pivot
3108 //return error cannot pivot and h flip
3109 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3110 break;
3111
3112 case 12:
3113 //vh flip
3114 //return an error, cannot rotate and VH flip a trans sprite
3115 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3116 break;
3117
3118 case 13:
3119 //trans + vh flip
3120 //return an error, cannot rotate and VH flip a trans sprite
3121 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3122 break;
3123
3124 case 14:
3125 //pivot and vh flip
3126 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3127 //return error cannot both pivot and vh flip
3128 break;
3129
3130 case 16:
3131 //lit
3132 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3133 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3134 break;
3135
3136 case 18:
3137 //pivot, lit
3138 //return an error, cannot both rotate and pivot
3139 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3140 break;
3141
3142 case 20:
3143 //lit + vflip
3144 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3145 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3146 break;
3147
3148 case 22:
3149 //Pivot, vflip, lit
3150 //return an error, cannot both rotate and pivot
3151 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3152 break;
3153
3154 case 24:
3155 //lit + h flip
3156 //return an error, cannot both rotate and H flip
3157 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3158 break;
3159
3160 case 26:
3161 //pivot + lit + hflip
3162 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3163 //return error cannot pivot, lit, and flip
3164 break;
3165
3166 case 28:
3167 //lit + vh flip
3168 //return an error, cannot both rotate and VH flip
3169 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3170 break;
3171
3172 case 32: //gouraud
3173 //Probably not wort supporting.
3174 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3175 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3176 break;
3177
3178 case 0:
3179 //no effect.
3180 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3181 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3182 break;
3183
3184 default:
3185 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3186
3187 }
3188 }
3189
3190 } //end if stretched, but not masked
3191 }
3192 else //not stretched
3193 {
3194
3195 if(masked) //if masked, but not stretched
3196 {
3197
3198 if ( rot == 0 ) //if not rotated
3199 {
3200 switch(mode)
3201 {
3202 case 1:
3203 //transparent
3204 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3205 draw_trans_sprite(bmp, subBmp, dx, dy);
3206 break;
3207
3208
3209 case 2:
3210 //pivot?
3211 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3212 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3213 //Pivoting requires two more args
3214 break;
3215
3216 case 3:
3217 //pivot + trans
3218 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3219 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3220 break;
3221
3222 case 4:
3223 //flip v
3224 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3225 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3226 break;
3227
3228 case 5:
3229 //trans + v flip
3230 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3231 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3232 break;
3233
3234 case 6:
3235 //pivot + v flip
3236 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3237 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3238 break;
3239
3240 case 8:
3241 //vlip h
3242 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3243 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3244 break;
3245
3246 case 9:
3247 //trans + h flip
3248 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3249 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3250 break;
3251
3252 case 10:
3253 //flip H and pivot
3254 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3255 //return error cannot pivot and h flip
3256 break;
3257
3258 case 12:
3259 //vh flip
3260 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3261 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3262 break;
3263
3264 case 13:
3265 //trans + vh flip
3266 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3267 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3268 break;
3269
3270 case 14:
3271 //pivot and vh flip
3272 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3273 //return error cannot both pivot and vh flip
3274 break;
3275
3276 case 16:
3277 //lit
3278 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3279 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3280 break;
3281
3282 case 18:
3283 //pivot, lit
3284 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3285 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3286 break;
3287
3288 case 20:
3289 //lit + v flip
3290 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3291 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3292 break;
3293
3294 case 22:
3295 //Pivot, vflip, lit
3296 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3297 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3298 break;
3299
3300 case 24:
3301 //lit + h flip
3302 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3303 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3304 break;
3305
3306 case 26:
3307 //pivot + lit + hflip
3308 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3309 //return error cannot pivot, lit, and flip
3310 break;
3311
3312 case 28:
3313 //lit + vh flip
3314 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3315 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3316 break;
3317
3318 case 32: //gouraud
3319 //Probably not wort supporting.
3320 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3321 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3322 break;
3323
3324 case 0:
3325 //no effect
3326 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3327 break;
3328
3329
3330 default:
3331 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3332
3333
3334 }
3335 } //end if not rotated
3336
3337 if ( rot != 0 ) //if rotated
3338 {
3339 switch(mode)
3340 {
3341 case 1:
3342 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3343 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3344
3345 break;
3346
3347 case 2:
3348 //pivot?
3349 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3350 //return an error, cannot both rotate and pivot
3351 break;
3352
3353 case 3:
3354 //pivot + trans
3355 //return an error, cannot both rotate and pivot
3356 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3357 break;
3358
3359 case 4:
3360 //flip v
3361 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3362 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3363 break;
3364
3365 case 5:
3366 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3367 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3368 break;
3369
3370 case 6:
3371 //pivot + v flip
3372 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3373 //return an error, cannot both rotate and pivot
3374 break;
3375
3376 case 8:
3377 //flip h
3378 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3379 //return an error, cannot both rotate and flip H
3380 break;
3381
3382 case 9:
3383 //trans + h flip
3384 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3385 //return an error, cannot rotate and flip a trans sprite
3386 break;
3387
3388 case 10:
3389 //flip H and pivot
3390 //return error cannot pivot and h flip
3391 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3392 break;
3393
3394 case 12:
3395 //vh flip
3396 //return an error, cannot rotate and VH flip a trans sprite
3397 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3398 break;
3399
3400 case 13:
3401 //trans + vh flip
3402 //return an error, cannot rotate and VH flip a trans sprite
3403 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3404 break;
3405
3406 case 14:
3407 //pivot and vh flip
3408 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3409 //return error cannot both pivot and vh flip
3410 break;
3411
3412 case 16:
3413 //lit
3414 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3415 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3416 break;
3417
3418 case 18:
3419 //pivot, lit
3420 //return an error, cannot both rotate and pivot
3421 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3422 break;
3423
3424 case 20:
3425 //lit + vflip
3426 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3427 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3428 break;
3429
3430 case 22:
3431 //Pivot, vflip, lit
3432 //return an error, cannot both rotate and pivot
3433 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3434 break;
3435
3436 case 24:
3437 //lit + h flip
3438 //return an error, cannot both rotate and H flip
3439 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3440 break;
3441
3442 case 26:
3443 //pivot + lit + hflip
3444 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3445 //return error cannot pivot, lit, and flip
3446 break;
3447
3448 case 28:
3449 //lit + vh flip
3450 //return an error, cannot both rotate and VH flip
3451 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3452 break;
3453
3454 case 32: //gouraud
3455 //Probably not wort supporting.
3456 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3457 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3458 break;
3459
3460 case 0:
3461 //no effect.
3462 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3463 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3464 break;
3465
3466 default:
3467 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3468
3469 }
3470 } //end rtated, masked
3471 } //end if masked
3472
3473 else //not masked, and not stretched; just blit
3474 {
3475
3476 if ( rot == 0 ) //if not rotated
3477 {
3478 switch(mode)
3479 {
3480 case 1:
3481 //transparent
3482 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3483 draw_trans_sprite(bmp, subBmp, dx, dy);
3484 break;
3485
3486
3487 case 2:
3488 //pivot?
3489 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3490 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3491 //Pivoting requires two more args
3492 break;
3493
3494 case 3:
3495 //pivot + trans
3496 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3497 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3498 break;
3499
3500 case 4:
3501 //flip v
3502 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3503 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3504 break;
3505
3506 case 5:
3507 //trans + v flip
3508 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3509 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3510 break;
3511
3512 case 6:
3513 //pivot + v flip
3514 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3515 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3516 break;
3517
3518 case 8:
3519 //vlip h
3520 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3521 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3522 break;
3523
3524 case 9:
3525 //trans + h flip
3526 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3527 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3528 break;
3529
3530 case 10:
3531 //flip H and pivot
3532 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3533 //return error cannot pivot and h flip
3534 break;
3535
3536 case 12:
3537 //vh flip
3538 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3539 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3540 break;
3541
3542 case 13:
3543 //trans + vh flip
3544 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3545 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3546 break;
3547
3548 case 14:
3549 //pivot and vh flip
3550 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3551 //return error cannot both pivot and vh flip
3552 break;
3553
3554 case 16:
3555 //lit
3556 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3557 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3558 break;
3559
3560 case 18:
3561 //pivot, lit
3562 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3563 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3564 break;
3565
3566 case 20:
3567 //lit + v flip
3568 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3569 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3570 break;
3571
3572 case 22:
3573 //Pivot, vflip, lit
3574 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3575 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3576 break;
3577
3578 case 24:
3579 //lit + h flip
3580 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3581 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3582 break;
3583
3584 case 26:
3585 //pivot + lit + hflip
3586 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3587 //return error cannot pivot, lit, and flip
3588 break;
3589
3590 case 28:
3591 //lit + vh flip
3592 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3593 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3594 break;
3595
3596 case 32: //gouraud
3597 //Probably not wort supporting.
3598 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3599 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3600 break;
3601
3602 case 0:
3603 //no effect
3604 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3605 break;
3606
3607
3608 default:
3609 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3610
3611
3612 }
3613 } //end if not rotated
3614
3615 if ( rot != 0 ) //if rotated
3616 {
3617 switch(mode)
3618 {
3619 case 1:
3620 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3621 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3622
3623 break;
3624
3625 case 2:
3626 //pivot?
3627 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3628 //return an error, cannot both rotate and pivot
3629 break;
3630
3631 case 3:
3632 //pivot + trans
3633 //return an error, cannot both rotate and pivot
3634 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3635 break;
3636
3637 case 4:
3638 //flip v
3639 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3640 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3641 break;
3642
3643 case 5:
3644 //trans + v flip
3645 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3646 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3647 break;
3648
3649 case 6:
3650 //pivot + v flip
3651 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3652 //return an error, cannot both rotate and pivot
3653 break;
3654
3655 case 8:
3656 //flip h
3657 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3658 //return an error, cannot both rotate and flip H
3659 break;
3660
3661 case 9:
3662 //trans + h flip
3663 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3664 //return an error, cannot rotate and flip a trans sprite
3665 break;
3666
3667 case 10:
3668 //flip H and pivot
3669 //return error cannot pivot and h flip
3670 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3671 break;
3672
3673 case 12:
3674 //vh flip
3675 //return an error, cannot rotate and VH flip a trans sprite
3676 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3677 break;
3678
3679 case 13:
3680 //trans + vh flip
3681 //return an error, cannot rotate and VH flip a trans sprite
3682 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3683 break;
3684
3685 case 14:
3686 //pivot and vh flip
3687 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3688 //return error cannot both pivot and vh flip
3689 break;
3690
3691 case 16:
3692 //lit
3693 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3694 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3695 break;
3696
3697 case 18:
3698 //pivot, lit
3699 //return an error, cannot both rotate and pivot
3700 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3701 break;
3702
3703 case 20:
3704 //lit + vflip
3705 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3706 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3707 break;
3708
3709 case 22:
3710 //Pivot, vflip, lit
3711 //return an error, cannot both rotate and pivot
3712 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3713 break;
3714
3715 case 24:
3716 //lit + h flip
3717 //return an error, cannot both rotate and H flip
3718 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3719 break;
3720
3721 case 26:
3722 //pivot + lit + hflip
3723 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3724 //return error cannot pivot, lit, and flip
3725 break;
3726
3727 case 28:
3728 //lit + vh flip
3729 //return an error, cannot both rotate and VH flip
3730 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3731 break;
3732
3733 case 32: //gouraud
3734 //Probably not wort supporting.
3735 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3736 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3737 break;
3738
3739 case 0:
3740 //no effect.
3741 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3742 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3743 break;
3744
3745 default:
3746 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3747
3748 }
3749 } //end if rotated
3750 } //end if not masked
3751 } //end if not stretched
3752
3753 //cleanup
3754 if(subBmp)
3755 {
3756 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3757 }
3758 }
3759
3760
3761 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3762 {
3763 //sdci[1]=layer
3764 //sdci[2]=pos[12]
3765 //sdci[3]=uv[8]
3766 //sdci[4]=color[4]
3767 //sdci[5]=size[2]
3768 //sdci[6]=flip
3769 //sdci[7]=tile/combo
3770 //sdci[8]=polytype
3771
3772 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3773
3774 if(!v_ptr)
3775 {
3776 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3777 return;
3778 }
3779
3780 std::vector<int32_t> &v = *v_ptr;
3781
3782 if(v.empty())
3783 return;
3784
3785 int32_t* pos = &v[0];
3786 int32_t* uv = &v[12];
3787 int32_t* col = &v[20];
3788 int32_t* size = &v[24];
3789
3790 int32_t w = size[0]; //magic numerical constants... yuck.
3791 int32_t h = size[1];
3792 int32_t flip = (sdci[6]/10000)&3;
3793 int32_t tile = sdci[7]/10000;
3794 int32_t polytype = sdci[8]/10000;
3795
3796 polytype = vbound(polytype, 0, 14);
3797
3798 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3799 {
3800 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3801 return; //non power of two error
3802 }
3803
3804 int32_t tex_width = w*16;
3805 int32_t tex_height = h*16;
3806
3807 bool mustDestroyBmp = false;
3808 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3809
3810 if(!tex)
3811 {
3812 mustDestroyBmp = true;
3813 tex = create_bitmap_ex(8, tex_width, tex_height);
3814 clear_bitmap(tex);
3815 }
3816
3817 if(tile > 0) // TILE
3818 {
3819 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3820 }
3821 else // COMBO
3822 {
3823 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
3824 const int32_t tiletodraw = combo_tile(c, 0, 0);
3825 flip = flip ^ c.flip;
3826
3827 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3828 }
3829
3830 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3831 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3832 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3833 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3834
3835 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3836
3837 if(mustDestroyBmp)
3838 destroy_bitmap(tex);
3839
3840 }
3841
3842
3843
3844 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3845 {
3846 //sdci[1]=layer
3847 //sdci[2]=pos[9]
3848 //sdci[3]=uv[6]
3849 //sdci[4]=color[3]
3850 //sdci[5]=size[2]
3851 //sdci[6]=flip
3852 //sdci[7]=tile/combo
3853 //sdci[8]=polytype
3854
3855 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3856
3857 if(!v_ptr)
3858 {
3859 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3860 return;
3861 }
3862
3863 std::vector<int32_t> &v = *v_ptr;
3864
3865 if(v.empty())
3866 return;
3867
3868 int32_t* pos = &v[0];
3869 int32_t* uv = &v[9];
3870 int32_t* col = &v[15];
3871 int32_t* size = &v[18];
3872
3873 int32_t w = size[0]; //magic numerical constants... yuck.
3874 int32_t h = size[1];
3875 int32_t flip = (sdci[6]/10000)&3;
3876 int32_t tile = sdci[7]/10000;
3877 int32_t polytype = sdci[8]/10000;
3878
3879 polytype = vbound(polytype, 0, 14);
3880
3881 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3882 {
3883 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3884 return; //non power of two error
3885 }
3886
3887 int32_t tex_width = w*16;
3888 int32_t tex_height = h*16;
3889
3890 bool mustDestroyBmp = false;
3891 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3892
3893 if(!tex)
3894 {
3895 mustDestroyBmp = true;
3896 tex = create_bitmap_ex(8, tex_width, tex_height);
3897 clear_bitmap(tex);
3898 }
3899
3900 if(tile > 0) // TILE
3901 {
3902 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3903 }
3904 else // COMBO
3905 {
3906 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
3907 const int32_t tiletodraw = combo_tile(c, 0, 0);
3908 flip = flip ^ c.flip;
3909
3910 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3911 }
3912
3913 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3914 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3915 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3916
3917 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3918
3919 if(mustDestroyBmp)
3920 destroy_bitmap(tex);
3921
3922 }
3923
3924 7971 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3925 {
3926 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3927 //sdci[1]=layer
3928 //sdci[2]=x
3929 //sdci[3]=y
3930 //sdci[4]=x2
3931 //sdci[5]=y2
3932 //sdci[6]=color
3933 //sdci[7]=scale factor
3934 //sdci[8]=rotation anchor x
3935 //sdci[9]=rotation anchor y
3936 //sdci[10]=rotation angle
3937 //sdci[11]=fill
3938 //sdci[12]=opacity
3939 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
3940
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7]==0) //scale
3941 {
3942 return;
3943 }
3944
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7971 times.
7971 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3945 {
3946 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3947 return;
3948 }
3949 7971 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
3950
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if ( refbmp == NULL ) return;
3951
3952
2/4
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7971 times.
7971 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3953
3954 7971 int32_t x1=sdci[2]/10000;
3955 7971 int32_t y1=sdci[3]/10000;
3956 7971 int32_t x2=sdci[4]/10000;
3957 7971 int32_t y2=sdci[5]/10000;
3958
3959
3960
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(x1>x2)
3961 {
3962 4 zc_swap(x1,x2);
3963 4 }
3964
3965
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(y1>y2)
3966 {
3967 4 zc_swap(y1,y2);
3968 4 }
3969
3970
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7] != 10000)
3971 {
3972 int32_t w=x2-x1+1;
3973 int32_t h=y2-y1+1;
3974 int32_t w2=(w*sdci[7])/10000;
3975 int32_t h2=(h*sdci[7])/10000;
3976 x1=x1-((w2-w)/2);
3977 x2=x2+((w2-w)/2);
3978 y1=y1-((h2-h)/2);
3979 y2=y2+((h2-h)/2);
3980 }
3981
3982 7971 int32_t color=sdci[6]/10000;
3983
3984
2/2
✓ Branch 0 taken 7843 times.
✓ Branch 1 taken 128 times.
7971 if(sdci[12]/10000<=127) //translucent
3985 {
3986 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3987 128 }
3988
3989
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7875 times.
7971 if(sdci[10]==0) //no rotation
3990 {
3991
2/2
✓ Branch 0 taken 7863 times.
✓ Branch 1 taken 12 times.
7875 if(sdci[11]) //filled
3992 {
3993 7863 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3994 7863 }
3995 else //outline
3996 {
3997 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3998 }
3999 7875 }
4000 else //rotate
4001 {
4002 int32_t xy[16];
4003 96 int32_t rx=sdci[8]/10000;
4004 96 int32_t ry=sdci[9]/10000;
4005 96 fixed ra1=itofix(sdci[10]%10000)/10000;
4006 96 fixed ra2=itofix(sdci[10]/10000);
4007 96 fixed ra=ra1+ra2;
4008 96 ra = (ra/360)*256;
4009
4010 96 fixed fcosa = fixcos(ra);
4011 96 fixed fsina = fixsin(ra);
4012
4013 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
4014 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
4015 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
4016 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
4017 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
4018 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
4019 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
4020 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
4021 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
4022 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
4023 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
4024 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
4025 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
4026 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
4027 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
4028 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
4029
4030
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
4031 {
4032 96 polygon(refbmp, 4, xy, color);
4033 96 }
4034 else //outline
4035 {
4036 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
4037 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
4038 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
4039 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
4040 }
4041 }
4042
4043 7971 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4044 7971 }
4045
4046 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4047 {
4048 //sdci[1]=layer
4049 //sdci[2]=x
4050 //sdci[3]=y
4051 //sdci[4]=tile
4052 //sdci[5]=cset
4053 //sdci[6]=width
4054 //sdci[7]=height
4055 //sdci[8]=overlay
4056 //sdci[9]=opacity
4057
4058 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4059 {
4060 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4061 return;
4062 }
4063 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4064 if ( refbmp == NULL ) return;
4065
4066 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4067
4068 int32_t x=sdci[2]/10000;
4069 int32_t y=sdci[3]/10000;
4070
4071 int32_t tile=sdci[4]/10000;
4072 int32_t cs=sdci[5]/10000;
4073 int32_t w=sdci[6]/10000;
4074 int32_t h=sdci[7]/10000;
4075 bool overlay=sdci[8];
4076 bool trans=(sdci[9]/10000<=127);
4077
4078 frame2x2(refbmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4079 }
4080
4081
4082 148823 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4083 {
4084 //sdci[1]=layer
4085 //sdci[2]=x
4086 //sdci[3]=y
4087 //sdci[4]=radius
4088 //sdci[5]=color
4089 //sdci[6]=scale factor
4090 //sdci[7]=rotation anchor x
4091 //sdci[8]=rotation anchor y
4092 //sdci[9]=rotation angle
4093 //sdci[10]=fill
4094 //sdci[11]=opacity
4095 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4096
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6]==0) //scale
4097 {
4098 return;
4099 }
4100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
148823 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4101 {
4102 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4103 return;
4104 }
4105 148823 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4106
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if ( refbmp == NULL ) return;
4107
4108
2/4
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 148823 times.
148823 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4109
4110 148823 int32_t x1=sdci[2]/10000;
4111 148823 int32_t y1=sdci[3]/10000;
4112 148823 qword r=sdci[4];
4113
4114
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6] != 10000)
4115 {
4116 r*=sdci[6];
4117 r/=10000;
4118 }
4119
4120 148823 r/=10000;
4121 148823 int32_t color=sdci[5]/10000;
4122
4123
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[11]/10000<=127) //translucent
4124 {
4125 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4126 }
4127
4128
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148823 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4129 {
4130 int32_t xy[2];
4131 int32_t rx=sdci[7]/10000;
4132 int32_t ry=sdci[8]/10000;
4133 fixed ra1=itofix(sdci[9]%10000)/10000;
4134 fixed ra2=itofix(sdci[9]/10000);
4135 fixed ra=ra1+ra2;
4136 ra = (ra/360)*256;
4137
4138 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4139 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4140 x1=xy[0];
4141 y1=xy[1];
4142 }
4143
4144
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[10]) //filled
4145 {
4146 148823 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4147 148823 }
4148 else //outline
4149 {
4150 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4151 }
4152
4153 148823 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4154 148823 }
4155
4156
4157 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4158 {
4159 //sdci[1]=layer
4160 //sdci[2]=x
4161 //sdci[3]=y
4162 //sdci[4]=radius
4163 //sdci[5]=start angle
4164 //sdci[6]=end angle
4165 //sdci[7]=color
4166 //sdci[8]=scale factor
4167 //sdci[9]=rotation anchor x
4168 //sdci[10]=rotation anchor y
4169 //sdci[11]=rotation angle
4170 //sdci[12]=closed
4171 //sdci[13]=fill
4172 //sdci[14]=opacity
4173 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4174
4175 if(sdci[8]==0) //scale
4176 {
4177 return;
4178 }
4179 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4180 {
4181 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4182 return;
4183 }
4184 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4185 if ( refbmp == NULL ) return;
4186
4187 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4188
4189 int32_t cx=sdci[2]/10000;
4190 int32_t cy=sdci[3]/10000;
4191 qword r=sdci[4];
4192
4193 if(sdci[8] != 10000)
4194 {
4195 r*=sdci[8];
4196 r/=10000;
4197 }
4198
4199 r/=10000;
4200
4201 int32_t color=sdci[7]/10000;
4202
4203 fixed ra1=itofix(sdci[11]%10000)/10000;
4204 fixed ra2=itofix(sdci[11]/10000);
4205 fixed ra=ra1+ra2;
4206 ra = (ra/360)*256;
4207
4208
4209 fixed a1=itofix(sdci[5]%10000)/10000;
4210 fixed a2=itofix(sdci[5]/10000);
4211 fixed sa=a1+a2;
4212 sa = (sa/360)*256;
4213
4214 a1=itofix(sdci[6]%10000)/10000;
4215 a2=itofix(sdci[6]/10000);
4216 fixed ea=a1+a2;
4217 ea = (ea/360)*256;
4218
4219 if(sdci[11]!=0) //rotation
4220 {
4221 int32_t rx=sdci[9]/10000;
4222 int32_t ry=sdci[10]/10000;
4223
4224 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4225 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4226 ea-=ra;
4227 sa-=ra;
4228 }
4229
4230 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4231 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4232
4233 if(sdci[12]) //closed
4234 {
4235 if(sdci[13]) //filled
4236 {
4237 clear_bitmap(prim_bmp);
4238 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4239 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4240 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4241 int fillx = zc_max(0,fx)+xoffset;
4242 int filly = zc_max(0,fy)+yoffset;
4243 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4244 floodfill(prim_bmp, fillx, filly, color);
4245
4246 if(sdci[14]/10000<=127) //translucent
4247 {
4248 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4249 }
4250 else
4251 {
4252 draw_sprite(refbmp, prim_bmp, 0,0);
4253 }
4254 }
4255 else
4256 {
4257 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4258 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4259 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4260 }
4261 }
4262 else
4263 {
4264 if(sdci[14]/10000<=127) //translucent
4265 {
4266 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4267 }
4268
4269 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4270 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4271 }
4272 }
4273
4274
4275 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4276 {
4277 //sdci[1]=layer
4278 //sdci[2]=x
4279 //sdci[3]=y
4280 //sdci[4]=radiusx
4281 //sdci[5]=radiusy
4282 //sdci[6]=color
4283 //sdci[7]=scale factor
4284 //sdci[8]=rotation anchor x
4285 //sdci[9]=rotation anchor y
4286 //sdci[10]=rotation angle
4287 //sdci[11]=fill
4288 //sdci[12]=opacity
4289 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4290
4291
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4292 {
4293 return;
4294 }
4295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4296 {
4297 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4298 return;
4299 }
4300 502 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4301
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4302
4303 502 int32_t x1=sdci[2]/10000;
4304 502 int32_t y1=sdci[3]/10000;
4305 502 int32_t radx=sdci[4]/10000;
4306 502 radx*=sdci[7]/10000;
4307 502 int32_t rady=sdci[5]/10000;
4308 502 rady*=sdci[7]/10000;
4309 502 int32_t color=sdci[6]/10000;
4310 502 float rotation = sdci[10]/10000;
4311
4312 502 int32_t rx=sdci[8]/10000;
4313 502 int32_t ry=sdci[9]/10000;
4314 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4315 502 fixed ra2=itofix(sdci[10]/10000);
4316 502 fixed ra=ra1+ra2;
4317 502 ra = (ra/360)*256;
4318
4319
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4320
4321 int32_t xy[2];
4322 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4323 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4324 502 x1=xy[0];
4325 502 y1=xy[1];
4326
4327
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4328
4329 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4330
4331
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4332
4333
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4334 {
4335
4336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4337 {
4338 clear_bitmap(prim_bmp);
4339 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4340 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4341 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4342 }
4343 else // no opacity
4344 {
4345
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4346 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4347 }
4348 494 }
4349 else //not filled
4350 {
4351 if(sdci[12]/10000<128) //translucent
4352 {
4353 clear_bitmap(prim_bmp);
4354 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4355 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4356 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4357 }
4358 else // no opacity
4359 {
4360 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4361 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4362 }
4363 }
4364
4365 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4366 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4367 // the ellipse, but it shouldn't be used anyway.
4368
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4369 {
4370 // This is very slow, so check the smallest possible square
4371
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4372
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4373
4374
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4375
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 4430 times.
✓ Branch 2 taken 1086 times.
✓ Branch 3 taken 3344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1086 times.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4376
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4377 233212 putpixel(refbmp, x, y, 0);
4378 62 }
4379
4380 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4381 502 }
4382
4383
4384 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4385 {
4386 //sdci[1]=layer
4387 //sdci[2]=x
4388 //sdci[3]=y
4389 //sdci[4]=x2
4390 //sdci[5]=y2
4391 //sdci[6]=color
4392 //sdci[7]=scale factor
4393 //sdci[8]=rotation anchor x
4394 //sdci[9]=rotation anchor y
4395 //sdci[10]=rotation angle
4396 //sdci[11]=opacity
4397 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4398
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4399 {
4400 return;
4401 }
4402
4403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4404 {
4405 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4406 return;
4407 }
4408
4409 144 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4410
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4411
4412 144 int32_t x1=sdci[2]/10000;
4413 144 int32_t y1=sdci[3]/10000;
4414 144 int32_t x2=sdci[4]/10000;
4415 144 int32_t y2=sdci[5]/10000;
4416
4417
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4418 {
4419 int32_t w=x2-x1+1;
4420 int32_t h=y2-y1+1;
4421 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4422 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4423 x1=x1-((w2-w)/2);
4424 x2=x2+((w2-w)/2);
4425 y1=y1-((h2-h)/2);
4426 y2=y2+((h2-h)/2);
4427 }
4428
4429 144 int32_t color=sdci[6]/10000;
4430
4431
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4432
4433
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4434 {
4435 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4436 }
4437
4438
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4439 {
4440 int32_t xy[4];
4441 int32_t rx=sdci[8]/10000;
4442 int32_t ry=sdci[9]/10000;
4443 fixed ra1=itofix(sdci[10]%10000)/10000;
4444 fixed ra2=itofix(sdci[10]/10000);
4445 fixed ra=ra1+ra2;
4446
4447 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4448 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4449 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4450 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4451 x1=xy[0];
4452 y1=xy[1];
4453 x2=xy[2];
4454 y2=xy[3];
4455 }
4456
4457 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4458 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4459 144 }
4460
4461
4462 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4463 {
4464 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4465 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4466
4467 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4468 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4469 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4470 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4471 };
4472
4473 if(sdci[11]/10000 < 128) //translucent
4474 {
4475 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4476 }
4477
4478 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4479 {
4480 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4481 return;
4482 }
4483
4484 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4485 if ( refbmp == NULL ) return;
4486
4487 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4488
4489 spline(refbmp, points, sdci[10]/10000);
4490
4491 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4492 }
4493
4494
4495 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4496 {
4497 //sdci[1]=layer
4498 //sdci[2]=x
4499 //sdci[3]=y
4500 //sdci[4]=color
4501 //sdci[5]=rotation anchor x
4502 //sdci[6]=rotation anchor y
4503 //sdci[7]=rotation angle
4504 //sdci[8]=opacity
4505 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4506 80910 int32_t x1=sdci[2]/10000;
4507 80910 int32_t y1=sdci[3]/10000;
4508 80910 int32_t color=sdci[4]/10000;
4509
4510
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4511 {
4512 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4513 }
4514
4515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4516 {
4517 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4518 return;
4519 }
4520
4521 80910 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4522
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4523
4524
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4525
4526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4527 {
4528 int32_t xy[2];
4529 int32_t rx=sdci[5]/10000;
4530 int32_t ry=sdci[6]/10000;
4531 fixed ra1=itofix(sdci[7]%10000)/10000;
4532 fixed ra2=itofix(sdci[7]/10000);
4533 fixed ra=ra1+ra2;
4534
4535 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4536 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4537 x1=xy[0];
4538 y1=xy[1];
4539 }
4540
4541 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4542 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4543 80910 }
4544
4545
4546 59816 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4547 {
4548 //sdci[1]=layer
4549 //sdci[2]=x
4550 //sdci[3]=y
4551 //sdci[4]=tile
4552 //sdci[5]=tile width
4553 //sdci[6]=tile height
4554 //sdci[7]=color (cset)
4555 //sdci[8]=scale x
4556 //sdci[9]=scale y
4557 //sdci[10]=rotation anchor x
4558 //sdci[11]=rotation anchor y
4559 //sdci[12]=rotation angle
4560 //sdci[13]=flip
4561 //sdci[14]=transparency
4562 //sdci[15]=opacity
4563 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4564
4565 59816 int32_t w = sdci[5]/10000;
4566 59816 int32_t h = sdci[6]/10000;
4567
4568
4/8
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59816 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59816 times.
59816 if(w < 1 || h < 1 || h > 20 || w > 20)
4569 {
4570 return;
4571 }
4572
4573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4574 {
4575 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4576 return;
4577 }
4578
4579 59816 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( refbmp == NULL ) return;
4581
4582 59816 int32_t xscale=sdci[8]/10000;
4583 59816 int32_t yscale=sdci[9]/10000;
4584 59816 int32_t rx = sdci[10]/10000;
4585 59816 int32_t ry = sdci[11]/10000;
4586 59816 float rotation=sdci[12]/10000;
4587 59816 int32_t flip=(sdci[13]/10000)&3;
4588 59816 bool transparency=sdci[14]!=0;
4589 59816 int32_t opacity=sdci[15]/10000;
4590 59816 int32_t color=sdci[7]/10000;
4591
4592 59816 int32_t x1=sdci[2]/10000;
4593 59816 int32_t y1=sdci[3]/10000;
4594
4595
4596 //don't scale if it's not safe to do so
4597 59816 bool canscale = true;
4598
4599
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if(xscale==0||yscale==0)
4600 {
4601 return;
4602 }
4603
4604
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59816 if(xscale<0||yscale<0)
4605 58910 canscale = false; //default size
4606
4607
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4608
4609
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 54302 times.
59816 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4610 {
4611 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4612
4613
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4614 {
4615 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4616 5514 }
4617 else //no transparency
4618 {
4619 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4620 }
4621
4622
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4623 {
4624 //low negative values indicate no anchor-point rotation
4625
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4626 {
4627 int32_t xy[2];
4628 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4629 4608 fixed ra2=itofix(sdci[12]/10000);
4630 4608 fixed ra=ra1+ra2;
4631 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4632 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4633 4608 x1=xy[0];
4634 4608 y1=xy[1];
4635 4608 }
4636
4637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4638 {
4639 //damnit all, .. fixme.
4640 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4641 clear_bitmap(tempbit);
4642
4643 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4644
4645 if(opacity < 128)
4646 {
4647 clear_bitmap(prim_bmp);
4648 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4649 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4650 }
4651 else
4652 {
4653 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4654 }
4655
4656 destroy_bitmap(tempbit);
4657 }
4658 else //no scale
4659 {
4660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4661 {
4662 clear_bitmap(prim_bmp);
4663 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4664 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4665 }
4666 else
4667 {
4668 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4669 }
4670 }
4671 4608 }
4672 else //scale only
4673 {
4674
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4675 {
4676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4677 {
4678 clear_bitmap(prim_bmp);
4679 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4680 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4681 }
4682 else
4683 {
4684 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4685 }
4686 906 }
4687 else //error -do not scale
4688 {
4689 if(opacity<128)
4690 {
4691 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4692 }
4693 else
4694 {
4695 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4696 }
4697 }
4698 }
4699
4700 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4701
4702 5514 }
4703 else // no scale or rotation
4704 {
4705
2/2
✓ Branch 0 taken 45964 times.
✓ Branch 1 taken 8338 times.
54302 if(transparency)
4706 {
4707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45964 times.
45964 if(opacity<=127)
4708 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4709 else
4710 45964 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4711 45964 }
4712 else
4713 {
4714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8338 times.
8338 if(opacity<=127)
4715 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4716 else
4717 8338 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4718 }
4719 }
4720 59816 }
4721
4722 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4723 {
4724 //sdci[1]=layer
4725 //sdci[2]=x
4726 //sdci[3]=y
4727 //sdci[4]=tile
4728 //sdci[5]=tile width
4729 //sdci[6]=tile height
4730 //sdci[7]=flip
4731 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4732
4733 int32_t w = sdci[5]/10000;
4734 int32_t h = sdci[6]/10000;
4735
4736 if(w < 1 || h < 1 || h > 20 || w > 20)
4737 {
4738 return;
4739 }
4740
4741 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4742 {
4743 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4744 return;
4745 }
4746
4747 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4748 if ( refbmp == NULL ) return;
4749
4750 int32_t flip=(sdci[7]/10000)&3;
4751
4752 int32_t x1=sdci[2]/10000;
4753 int32_t y1=sdci[3]/10000;
4754
4755 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4756
4757 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4758 }
4759
4760
4761 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4762 {
4763 //sdci[1]=layer
4764 //sdci[2]=x
4765 //sdci[3]=y
4766 //sdci[4]=combo
4767 //sdci[5]=tile width
4768 //sdci[6]=tile height
4769 //sdci[7]=color (cset)
4770 //sdci[8]=scale x
4771 //sdci[9]=scale y
4772 //sdci[10]=rotation anchor x
4773 //sdci[11]=rotation anchor y
4774 //sdci[12]=rotation angle
4775 //sdci[13]=frame
4776 //sdci[14]=flip
4777 //sdci[15]=transparency
4778 //sdci[16]=opacity
4779 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4780 824 int32_t w = sdci[5]/10000;
4781 824 int32_t h = sdci[6]/10000;
4782
4783
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4784 {
4785 return;
4786 }
4787
4788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4789 {
4790 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4791 return;
4792 }
4793
4794 824 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4795
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4796 824 int32_t cmb = (sdci[4]/10000);
4797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4798 {
4799 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4800 return;
4801 }
4802
4803 824 int32_t xscale=sdci[8]/10000;
4804 824 int32_t yscale=sdci[9]/10000;
4805 824 int32_t rx = sdci[10]/10000; //these work now
4806 824 int32_t ry = sdci[11]/10000; //these work now
4807 824 float rotation=sdci[12]/10000;
4808
4809 824 bool transparency=sdci[15]!=0;
4810 824 int32_t opacity=sdci[16]/10000;
4811 824 int32_t color=sdci[7]/10000;
4812 824 int32_t x1=sdci[2]/10000;
4813 824 int32_t y1=sdci[3]/10000;
4814
4815 824 auto& c = GET_DRAWING_COMBO(cmb);
4816 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4817 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4818 824 int32_t skiprows=c.skipanimy;
4819
4820
4821 //don't scale if it's not safe to do so
4822 824 bool canscale = true;
4823
4824
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4825 {
4826 return;
4827 }
4828
4829
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4830 824 canscale = false; //default size
4831
4832
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4833
4834
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4835 {
4836 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4837
4838 if(transparency)
4839 {
4840 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4841 }
4842 else //no transparency
4843 {
4844 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4845 }
4846
4847 if(rotation != 0) // rotate
4848 {
4849 //fixed point sucks ;0
4850 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4851 {
4852 int32_t xy[2];
4853 fixed ra1=itofix(sdci[12]%10000)/10000;
4854 fixed ra2=itofix(sdci[12]/10000);
4855 fixed ra=ra1+ra2;
4856 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4857 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4858 x1=xy[0];
4859 y1=xy[1];
4860 }
4861
4862 if(canscale) //scale first
4863 {
4864 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4865 clear_bitmap(tempbit);
4866
4867 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4868
4869 if(opacity < 128)
4870 {
4871 clear_bitmap(prim_bmp);
4872 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4873 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4874 }
4875 else
4876 {
4877 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4878 }
4879
4880 destroy_bitmap(tempbit);
4881 }
4882 else //no scale
4883 {
4884 if(opacity < 128)
4885 {
4886 clear_bitmap(prim_bmp);
4887 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4888 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4889 }
4890 else
4891 {
4892 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4893 }
4894 }
4895 }
4896 else //scale only
4897 {
4898 if(canscale)
4899 {
4900 if(opacity<128)
4901 {
4902 clear_bitmap(prim_bmp);
4903 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4904 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4905 }
4906 else
4907 {
4908 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4909 }
4910 }
4911 else //error -do not scale
4912 {
4913 if(opacity<128)
4914 {
4915 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4916 }
4917 else
4918 {
4919 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4920 }
4921 }
4922 }
4923
4924 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4925 }
4926 else // no scale or rotation
4927 {
4928
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4929 {
4930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4931 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4932 else
4933 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4934 824 }
4935 else
4936 {
4937 if(opacity<=127)
4938 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4939 else
4940 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4941 }
4942 }
4943 824 }
4944
4945
4946 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4947 {
4948 //sdci[1]=layer
4949 //sdci[2]=x
4950 //sdci[3]=y
4951 //sdci[4]=combo
4952 //sdci[5]=tile width
4953 //sdci[6]=tile height
4954 //sdci[7]=flip
4955 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4956
4957 int32_t w = sdci[5]/10000;
4958 int32_t h = sdci[6]/10000;
4959
4960 if(w<1||h<1||h>20||w>20)
4961 {
4962 return;
4963 }
4964
4965 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4966 {
4967 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4968 return;
4969 }
4970
4971 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4972 if ( refbmp == NULL ) return;
4973 int32_t cmb = (sdci[4]/10000);
4974 if((unsigned)cmb >= MAXCOMBOS)
4975 {
4976 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4977 return;
4978 }
4979
4980 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4981
4982 int32_t x1=sdci[2]/10000;
4983 int32_t y1=sdci[3]/10000;
4984
4985 auto& c = GET_DRAWING_COMBO(cmb);
4986 int32_t tiletodraw = combo_tile(c, x1, y1);
4987 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4988 int32_t skiprows=c.skipanimy;
4989
4990 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
4991 }
4992
4993
4994 168443 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4995 {
4996 /* layer, x, y, tile, color opacity */
4997 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4998
4999 168443 int32_t opacity = sdci[6]/10000;
5000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168443 times.
168443 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5001 {
5002 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5003 return;
5004 }
5005 168443 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5006
1/2
✓ Branch 0 taken 168443 times.
✗ Branch 1 not taken.
168443 if ( refbmp == NULL ) return;
5007
5008
2/4
✓ Branch 0 taken 168443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168443 times.
✗ Branch 3 not taken.
168443 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5009
5010 168443 int x = xoffset+(sdci[2]/10000);
5011 168443 int y = yoffset+(sdci[3]/10000);
5012
5013
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 157312 times.
168443 if(opacity < 128)
5014 11131 overtiletranslucent16(refbmp, sdci[4]/10000, x, y, sdci[5]/10000, 0, opacity);
5015 else
5016 157312 overtile16(refbmp, sdci[4]/10000, x, y, sdci[5]/10000, 0);
5017 168443 }
5018
5019 19821648 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5020 {
5021 /* layer, x, y, tile, is8bit, mask */
5022 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5023
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19821648 times.
19821648 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5024 {
5025 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5026 return;
5027 }
5028 19821648 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5029
1/2
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
19821648 if ( refbmp == NULL ) return;
5030
5031
2/4
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19821648 times.
✗ Branch 3 not taken.
19821648 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5032
5033 19821648 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
5034 19821648 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
5035
5036 19821648 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
5037 19821648 }
5038
5039 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5040 {
5041 /* layer, mask, color, ditherType, ditherArg */
5042 //sdci[2] Mask Bitmap Pointer
5043 //sdci[3] Color
5044 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5045 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5046 {
5047 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5048 return;
5049 }
5050 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5051 if ( refbmp == NULL ) return;
5052 if ( sdci[2] <= 0 )
5053 {
5054 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5055 return;
5056 }
5057 BITMAP *mask = resolveScriptingBitmap(sdci[2]);
5058 if ( mask == NULL ) return;
5059
5060 int32_t dType = sdci[4] / 10000L;
5061 if(dType < 0 || dType >= dithMax)
5062 {
5063 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
5064 return;
5065 }
5066
5067 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
5068 }
5069
5070 7323 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5071 {
5072 /* layer, shift, startcol, endcol */
5073 //sdci[2] NewCol
5074 //sdci[3] StartCol
5075 //sdci[4] EndCol
5076 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7323 times.
7323 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5078 {
5079 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5080 return;
5081 }
5082 7323 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5083
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7323 times.
7323 if ( refbmp == NULL ) return;
5084 7323 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5085 7323 }
5086
5087 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5088 {
5089 /* layer, shift, startcol, endcol */
5090 //sdci[2] ShiftAmount
5091 //sdci[3] StartCol
5092 //sdci[4] EndCol
5093 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5094 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5095 {
5096 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5097 return;
5098 }
5099 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5100 if ( refbmp == NULL ) return;
5101 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5102 }
5103
5104 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5105 {
5106 /* layer, mask, color */
5107 //sdci[2] Mask Bitmap Pointer
5108 //sdci[3] Color
5109 //sdci[4] start mask color
5110 //sdci[5] end mask color
5111 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5112 906 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5113
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5114 {
5115 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5116 return;
5117 }
5118 906 BITMAP *mask = resolveScriptingBitmap(sdci[2]);
5119
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5120 {
5121 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5122 return;
5123 }
5124 906 auto fillcol = sdci[3]/10000L;
5125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5126 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5127 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5128 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5129 906 }
5130
5131 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5132 {
5133 /* layer, mask, color */
5134 //sdci[2] Mask Bitmap Pointer
5135 //sdci[3] Pattern Bitmap
5136 //sdci[4] bool 'pattern repeats'
5137 //sdci[5] start mask color
5138 //sdci[6] end mask color
5139 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5140 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5141 if ( refbmp == NULL )
5142 {
5143 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5144 return;
5145 }
5146 BITMAP *mask = resolveScriptingBitmap(sdci[2]);
5147 if ( mask == NULL )
5148 {
5149 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5150 return;
5151 }
5152 BITMAP *pattern = resolveScriptingBitmap(sdci[3]);
5153 if ( pattern == NULL )
5154 {
5155 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5156 return;
5157 }
5158 bool repeats = sdci[4]!=0;
5159 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5160 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5161 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5162 }
5163
5164 32636464 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5165 {
5166 /* layer, x, y, tile, color opacity */
5167 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5168 32636464 int32_t opacity = sdci[6] / 10000;
5169 32636464 int32_t x1 = sdci[2] / 10000;
5170 32636464 int32_t y1 = sdci[3] / 10000;
5171 32636464 int32_t index = sdci[4]/10000;
5172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5173 {
5174 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5175 return;
5176 }
5177 32636464 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5178
1/2
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
32636464 if ( refbmp == NULL ) return;
5179 32636464 int32_t cmb = (sdci[4]/10000);
5180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if((unsigned)cmb >= MAXCOMBOS)
5181 {
5182 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5183 return;
5184 }
5185
5186
2/4
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32636464 times.
✗ Branch 3 not taken.
32636464 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5187
5188 32636464 int x = xoffset+x1;
5189 32636464 int y = yoffset+y1;
5190
5191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(opacity < 128)
5192 {
5193 overcomboblocktranslucent(refbmp, x, y, cmb, sdci[5]/10000, 1, 1, 128);
5194
5195 }
5196 else
5197 {
5198 32636464 overcomboblock(refbmp, x, y, cmb, sdci[5]/10000, 1, 1);
5199 }
5200 32636464 }
5201
5202
5203
5204 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5205 {
5206 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5207 {
5208 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5209 return;
5210 }
5211 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5212 if ( refbmp == NULL ) return;
5213
5214 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5215
5216 //broken 2.50.2 and earlier drawcharacter()
5217 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5218 {
5219 //sdci[1]=layer
5220 //sdci[2]=x
5221 //sdci[3]=y
5222 //sdci[4]=font
5223 //sdci[5]=color
5224 //sdci[6]=bg color
5225 //sdci[7]=strech x (width)
5226 //sdci[8]=stretch y (height)
5227 //sdci[9]=char
5228 //sdci[10]=opacity
5229 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5230
5231 int32_t x=sdci[2]/10000;
5232 int32_t y=sdci[3]/10000;
5233 int32_t font_index=sdci[4]/10000;
5234 int32_t color=sdci[5]/10000;
5235 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5236 int32_t w=sdci[7]/10000;
5237 int32_t h=sdci[8]/10000;
5238 char glyph=char(sdci[9]/10000);
5239 int32_t opacity=sdci[10]/10000;
5240
5241 //safe check
5242 if(bg_color < -1) bg_color = -1;
5243
5244 if(w>512) w=512; //w=vbound(w,0,512);
5245
5246 if(h>512) h=512; //h=vbound(h,0,512);
5247
5248 //undone
5249 if(w>0&&h>0)//stretch the character
5250 {
5251 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5252
5253 if(opacity < 128)
5254 {
5255 if(w>128||h>128)
5256 {
5257 clear_bitmap(prim_bmp);
5258
5259 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5260 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5261 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5262 }
5263 else //this is faster
5264 {
5265 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5266
5267 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5268 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5269 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5270
5271 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5272 }
5273 }
5274 else // no opacity
5275 {
5276 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5277 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5278 }
5279
5280 }
5281 else //no stretch
5282 {
5283 if(opacity < 128)
5284 {
5285 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5286 clear_bitmap(pbmp);
5287
5288 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5289 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5290
5291 destroy_bitmap(pbmp);
5292 }
5293 else // no opacity
5294 {
5295 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5296 }
5297 }
5298 }
5299
5300 else //2.53.0 fixed version and later.
5301 {
5302
5303 //sdci[1]=layer
5304 //sdci[2]=x
5305 //sdci[3]=y
5306 //sdci[4]=font
5307 //sdci[5]=color
5308 //sdci[6]=bg color
5309 //sdci[7]=strech x (width)
5310 //sdci[8]=stretch y (height)
5311 //sdci[9]=char
5312 //sdci[10]=opacity
5313
5314 int32_t x=sdci[2]/10000;
5315 int32_t y=sdci[3]/10000;
5316 int32_t font_index=sdci[4]/10000;
5317 int32_t color=sdci[5]/10000;
5318 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5319 int32_t w=sdci[7]/10000;
5320 int32_t h=sdci[8]/10000;
5321 char glyph=char(sdci[9]/10000);
5322 int32_t opacity=sdci[10]/10000;
5323
5324 //safe check
5325 if(bg_color < -1) bg_color = -1;
5326
5327 if(w>512) w=512; //w=vbound(w,0,512);
5328
5329 if(h>512) h=512; //h=vbound(h,0,512);
5330
5331 //undone
5332 if(w>0&&h>0)//stretch the character
5333 {
5334 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5335
5336 if(opacity < 128)
5337 {
5338 if(w>128||h>128)
5339 {
5340 clear_bitmap(prim_bmp);
5341
5342 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5343 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5344 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5345 }
5346 else //this is faster
5347 {
5348 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5349
5350 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5351 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5352 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5353
5354 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5355 }
5356 }
5357 else // no opacity
5358 {
5359 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5360 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5361 }
5362
5363 }
5364 else //no stretch
5365 {
5366 if(opacity < 128)
5367 {
5368 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5369 clear_bitmap(pbmp);
5370
5371 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5372 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5373
5374 destroy_bitmap(pbmp);
5375 }
5376 else // no opacity
5377 {
5378 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5379 }
5380 }
5381
5382 }
5383
5384 }
5385
5386
5387 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5388 {
5389 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5390 {
5391 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5392 return;
5393 }
5394 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5395 if ( refbmp == NULL ) return;
5396
5397 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5398
5399 //broken 2.50.2 and earlier drawinteger()
5400 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5401 {
5402 //sdci[1]=layer
5403 //sdci[2]=x
5404 //sdci[3]=y
5405 //sdci[4]=font
5406 //sdci[5]=color
5407 //sdci[6]=bg color
5408 //sdci[7]=strech x (width)
5409 //sdci[8]=stretch y (height)
5410 //sdci[9]=integer
5411 //sdci[10]=num decimal places
5412 //sdci[11]=opacity
5413 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5414
5415 int32_t x=sdci[2]/10000;
5416 int32_t y=sdci[3]/10000;
5417 int32_t font_index=sdci[4]/10000;
5418 int32_t color=sdci[5]/10000;
5419 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5420 int32_t w=sdci[7]/10000;
5421 int32_t h=sdci[8]/10000;
5422 int32_t decplace=sdci[10]/10000;
5423 int32_t opacity=sdci[11]/10000;
5424
5425 //safe check
5426 if(bg_color < -1) bg_color = -1;
5427
5428 if(w>512) w=512; //w=vbound(w,0,512);
5429
5430 if(h>512) h=512; //h=vbound(h,0,512);
5431
5432 char numbuf[15];
5433
5434 switch(decplace)
5435 {
5436 default:
5437 case 0:
5438 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5439 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5440
5441 case 1:
5442 //sprintf(numbuf,"%.01f",number);
5443 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5444 break;
5445
5446 case 2:
5447 //sprintf(numbuf,"%.02f",number);
5448 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5449 break;
5450
5451 case 3:
5452 //sprintf(numbuf,"%.03f",number);
5453 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5454 break;
5455
5456 case 4:
5457 //sprintf(numbuf,"%.04f",number);
5458 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5459 break;
5460 }
5461
5462 if(w>0&&h>0)//stretch
5463 {
5464 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5465
5466 if(opacity < 128)
5467 {
5468 if(w>128||h>128)
5469 {
5470 clear_bitmap(prim_bmp);
5471
5472 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5473 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5474 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5475 }
5476 else
5477 {
5478 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5479 clear_bitmap(pbmp2);
5480
5481 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5482 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5483 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5484
5485 destroy_bitmap(pbmp2);
5486 }
5487 }
5488 else // no opacity
5489 {
5490 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5491 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5492 }
5493
5494 }
5495 else //no stretch
5496 {
5497 if(opacity < 128)
5498 {
5499 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5500 clear_bitmap(pbmp);
5501
5502 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5503 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5504
5505 destroy_bitmap(pbmp);
5506 }
5507 else // no opacity
5508 {
5509 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5510 }
5511 }
5512
5513 }
5514
5515 else //2.53.0 fixed version and later.
5516 {
5517 //sdci[1]=layer
5518 //sdci[2]=x
5519 //sdci[3]=y
5520 //sdci[4]=font
5521 //sdci[5]=color
5522 //sdci[6]=bg color
5523 //sdci[7]=strech x (width)
5524 //sdci[8]=stretch y (height)
5525 //sdci[9]=integer
5526 //sdci[10]=num decimal places
5527 //sdci[11]=opacity
5528
5529 int32_t x=sdci[2]/10000;
5530 int32_t y=sdci[3]/10000;
5531 int32_t font_index=sdci[4]/10000;
5532 int32_t color=sdci[5]/10000;
5533 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5534 int32_t w=sdci[7]/10000;
5535 int32_t h=sdci[8]/10000;
5536 int32_t decplace=sdci[10]/10000;
5537 int32_t opacity=sdci[11]/10000;
5538
5539 //safe check
5540 if(bg_color < -1) bg_color = -1;
5541
5542 if(w>512) w=512; //w=vbound(w,0,512);
5543
5544 if(h>512) h=512; //h=vbound(h,0,512);
5545
5546 char numbuf[15];
5547
5548 switch(decplace)
5549 {
5550 default:
5551 case 0:
5552 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5553 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5554
5555 case 1:
5556 //sprintf(numbuf,"%.01f",number);
5557 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5558 break;
5559
5560 case 2:
5561 //sprintf(numbuf,"%.02f",number);
5562 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5563 break;
5564
5565 case 3:
5566 //sprintf(numbuf,"%.03f",number);
5567 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5568 break;
5569
5570 case 4:
5571 //sprintf(numbuf,"%.04f",number);
5572 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5573 break;
5574 }
5575
5576 //FONT* font=get_zc_font(sdci[4]/10000);
5577
5578 if(w>0&&h>0)//stretch
5579 {
5580 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5581 clear_bitmap(pbmp);
5582 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5583
5584 if(opacity < 128)
5585 {
5586 if(w>128||h>128)
5587 {
5588 clear_bitmap(prim_bmp);
5589
5590 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5591 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5592 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5593 }
5594 else
5595 {
5596 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5597 clear_bitmap(pbmp2);
5598
5599 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5600 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5601 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5602
5603 destroy_bitmap(pbmp2);
5604 }
5605 }
5606 else // no opacity
5607 {
5608 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5609 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5610 }
5611
5612 }
5613 else //no stretch
5614 {
5615 if(opacity < 128)
5616 {
5617 FONT* font = get_zc_font(font_index);
5618 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5619 clear_bitmap(pbmp);
5620
5621 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5622 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5623
5624 destroy_bitmap(pbmp);
5625 }
5626 else // no opacity
5627 {
5628 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5629 }
5630 }
5631 }
5632 }
5633
5634
5635 865 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5636 {
5637 //sdci[1]=layer
5638 //sdci[2]=x
5639 //sdci[3]=y
5640 //sdci[4]=font
5641 //sdci[5]=color
5642 //sdci[6]=bg color
5643 //sdci[7]=format_option
5644 //sdci[8]=string
5645 //sdci[9]=opacity
5646 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5648 {
5649 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5650 return;
5651 }
5652
5653 865 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5654
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if ( refbmp == NULL ) return;
5655
5656
2/4
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 865 times.
865 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5657
5658 865 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5659
5660
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if(!str)
5661 {
5662 al_trace("String pointer is null! Internal error. \n");
5663 return;
5664 }
5665
5666 865 int32_t x=sdci[2]/10000;
5667 865 int32_t y=sdci[3]/10000;
5668 865 FONT* font=get_zc_font(sdci[4]/10000);
5669 865 int32_t color=sdci[5]/10000;
5670 865 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5671 865 int32_t format_type=sdci[7]/10000;
5672 865 int32_t opacity=sdci[9]/10000;
5673 //sdci[8] not needed :)
5674
5675 //safe check
5676
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if(bg_color < -1) bg_color = -1;
5677
5678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if(opacity < 128)
5679 {
5680 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5681 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5682 clear_bitmap(pbmp);
5683 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5684 if(format_type == 2) // right-sided text
5685 x-=width;
5686 else if(format_type == 1) // centered text
5687 x-=width/2;
5688 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5689 destroy_bitmap(pbmp);
5690 }
5691 else // no opacity
5692 {
5693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if(format_type == 2) // right-sided text
5694 {
5695 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5696 }
5697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 else if(format_type == 1) // centered text
5698 {
5699 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5700 }
5701 else // standard left-sided text
5702 {
5703 865 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5704 }
5705 }
5706 865 }
5707
5708 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5709 {
5710 //sdci[1]=layer
5711 //sdci[2]=x
5712 //sdci[3]=y
5713 //sdci[4]=font
5714 //sdci[5]=color
5715 //sdci[6]=bg color
5716 //sdci[7]=format_option
5717 //sdci[8]=string
5718 //sdci[9]=opacity
5719 //sdci[10]=shadowtype
5720 //sdci[11]=shadow_color
5721 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5723 {
5724 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5725 return;
5726 }
5727
5728 45504 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5729
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5730
5731
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5732
5733 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5734
5735
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5736 {
5737 al_trace("String pointer is null! Internal error. \n");
5738 return;
5739 }
5740
5741 45504 int32_t x=sdci[2]/10000;
5742 45504 int32_t y=sdci[3]/10000;
5743 45504 FONT* font=get_zc_font(sdci[4]/10000);
5744 45504 int32_t color=sdci[5]/10000;
5745 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5746 45504 int32_t format_type=sdci[7]/10000;
5747 45504 int32_t opacity=sdci[9]/10000;
5748 45504 int32_t textstyle = sdci[10]/10000;
5749 45504 int32_t shadow_color = sdci[11]/10000;
5750 //sdci[8] not needed :)
5751
5752 //safe check
5753
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5754
5755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5756 {
5757 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5758 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5759 clear_bitmap(pbmp);
5760 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5761 if(format_type == 2) // right-sided text
5762 x-=width;
5763 else if(format_type == 1) // centered text
5764 x-=width/2;
5765 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5766 destroy_bitmap(pbmp);
5767 }
5768 else // no opacity
5769 {
5770 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5771 }
5772 45504 }
5773
5774 325125 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5775 {
5776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325125 times.
325125 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5777 {
5778 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5779 return;
5780 }
5781
5782 325125 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325125 times.
325125 if ( !refbmp ) return;
5784
5785 325125 clear_bitmap(refbmp);
5786 325125 }
5787
5788 3150 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5789 {
5790 //sdci[1]=layer
5791 //sdci[2]=color
5792 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5793 3150 int32_t pal_color = sdci[2]/10000;
5794
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5795 {
5796 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5797 return;
5798 }
5799
5800 3150 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if ( !refbmp ) return;
5802
5803 3150 clear_to_color(refbmp, pal_color);
5804 3150 }
5805
5806
5807 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5808 {
5809 //sdci[1]=layer
5810 34653 int32_t h = sdci[3]/10000;
5811 34653 int32_t w = sdci[2]/10000;
5812
1/2
✓ Branch 0 taken 34653 times.
✗ Branch 1 not taken.
34653 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
5813 {
5814 //flip height and width
5815 h = h ^ w;
5816 w = h ^ w;
5817 h = h ^ w;
5818 }
5819 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5820 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5822 {
5823 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5824 return;
5825 }
5826 34653 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5827 34653 auto& usr_bmp = scb.get(bitid);
5828
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( usr_bmp.u_bmp )
5829 34528 destroy_bitmap(usr_bmp.u_bmp);
5830 34653 usr_bmp.u_bmp = create_bitmap_ex(8,w,h);
5831
5832 34653 usr_bmp.width = w;
5833 34653 usr_bmp.height = h;
5834 34653 }
5835
5836 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5837 {
5838 //sdci[1]=layer
5839 //sdci[2]=filename
5840 //sdci[3]=y
5841 //sdci[4]=font
5842 //sdci[5]=color
5843 //sdci[6]=bg color
5844 //sdci[7]=format_option
5845 //sdci[8]=string
5846 //sdci[9]=opacity
5847 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5848 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5849 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5850 {
5851 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5852 return;
5853 }
5854 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5855 auto& usr_bitmap = scb.get(bitid);
5856 usr_bitmap.destroy();
5857
5858 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5859
5860 if(!str)
5861 {
5862 al_trace("String pointer is null! Internal error. \n");
5863 return;
5864 }
5865
5866 PALETTE tempPal;
5867 get_palette(tempPal);
5868 if ( checkPath(str->c_str(), false) )
5869 {
5870 usr_bitmap.u_bmp = load_bitmap(str->c_str(), tempPal);
5871 usr_bitmap.width = usr_bitmap.u_bmp->w;
5872 usr_bitmap.height = usr_bitmap.u_bmp->h;
5873 if ( !usr_bitmap.u_bmp )
5874 {
5875 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5876 }
5877 else
5878 {
5879 zprint("Read image file %s\n",str->c_str());
5880 }
5881 }
5882 else
5883 {
5884 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5885 usr_bitmap.u_bmp = create_bitmap_ex(8,256,176);
5886 clear_bitmap(usr_bitmap.u_bmp);
5887 }
5888 }
5889
5890
5891
5892 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5893 {
5894 //sdci[1]=layer
5895 //sdci[2]=filename
5896 //sdci[3]=y
5897 //sdci[4]=font
5898 //sdci[5]=color
5899 //sdci[6]=bg color
5900 //sdci[7]=format_option
5901 //sdci[8]=string
5902 //sdci[9]=opacity
5903 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5904 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5905
5906 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5907 {
5908 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5909 return;
5910 }
5911
5912 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5913 if ( !refbmp ) return;
5914
5915 bool overwrite = (sdci[3] != 0);
5916 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5917
5918 if(!str)
5919 {
5920 al_trace("String pointer is null! Internal error. \n");
5921 return;
5922 }
5923
5924 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5925 //std::strncpy(cptr, str->c_str(), str->size());
5926 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5927 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5928 if
5929 (
5930 ( (FFCore.checkExtension(*str, "")) ) ||
5931 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5932 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5933 )
5934 {
5935 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5936 }
5937 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5938 {
5939 if(make_dirs_for_file(*str))
5940 {
5941 save_bitmap(str->c_str(), refbmp, RAMpal);
5942 if(checkPath(str->c_str(), false))
5943 {
5944 zprint("Wrote image file %s\n",str->c_str());
5945 }
5946 else
5947 {
5948 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5949 }
5950 }
5951 else
5952 {
5953 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5954 }
5955 }
5956 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5957 }
5958
5959
5960 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5961 {
5962 //sdci[1]=layer
5963 //sdci[2]=x1
5964 //sdci[3]=y1
5965 //sdci[4]=x2
5966 //sdci[5]=y2
5967 //sdci[6]=x3
5968 //sdci[7]=y3
5969 //sdci[8]=x4
5970 //sdci[9]=y4
5971 //sdci[10]=width
5972 //sdci[11]=height
5973 //sdci[12]=cset
5974 //sdci[13]=flip
5975 //sdci[14]=tile/combo
5976 //sdci[15]=polytype
5977 //sdci[16] = other bitmap as texture
5978 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5979 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5980 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5981 {
5982 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5983 return;
5984 }
5985 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5986
5987 if ( !refbmp ) return;
5988
5989 int32_t x1 = sdci[2]/10000;
5990 int32_t y1 = sdci[3]/10000;
5991 int32_t x2 = sdci[4]/10000;
5992 int32_t y2 = sdci[5]/10000;
5993 int32_t x3 = sdci[6]/10000;
5994 int32_t y3 = sdci[7]/10000;
5995 int32_t x4 = sdci[8]/10000;
5996 int32_t y4 = sdci[9]/10000;
5997 int32_t w = sdci[10]/10000;
5998 int32_t h = sdci[11]/10000;
5999 int32_t color = sdci[12]/10000;
6000 int32_t flip=(sdci[13]/10000)&3;
6001 int32_t tile = sdci[14]/10000;
6002 int32_t polytype = sdci[15]/10000;
6003 int32_t quad_render_source = sdci[16];
6004 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
6005
6006 bool tex_is_bitmap = ( sdci[16] != 0 );
6007
6008 BITMAP *bmptexture=NULL;
6009 BITMAP *tex=NULL;
6010 polytype = vbound(polytype, 0, 14);
6011
6012 int32_t col[4];
6013 col[0]=col[1]=col[2]=col[3]=color;
6014 bool mustDestroyBmp = false;
6015
6016 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6017
6018 if ( tex_is_bitmap )
6019 {
6020 bmptexture = resolveScriptingBitmap(quad_render_source);
6021 if ( !bmptexture )
6022 {
6023 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6024 tex_is_bitmap = 0;
6025 }
6026 }
6027
6028 if ( tex_is_bitmap )
6029 {
6030
6031 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6032 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6033 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
6034 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
6035
6036 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6037 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6038 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6039 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6040
6041 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
6042 }
6043 else
6044 {
6045 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6046 if(!tex)
6047 {
6048 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
6049 mustDestroyBmp = true;
6050 tex = create_bitmap_ex(8, w*16, h*16);
6051 clear_bitmap(tex);
6052 }
6053
6054 if(tile > 0) // TILE
6055 {
6056 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6057 }
6058
6059 if ( tile < 0 ) // COMBO
6060 {
6061 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
6062 const int32_t tiletodraw = combo_tile(c, x1, y1);
6063 flip = flip ^ c.flip;
6064
6065 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6066 }
6067 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6068 {
6069 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6070 return; //non power of two error
6071 }
6072 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6073 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6074 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6075 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6076 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6077
6078 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6079
6080 }
6081
6082
6083
6084
6085 //todo: finish palette shading
6086 /*
6087 POLYTYPE_FLAT
6088 POLYTYPE_GCOL
6089 POLYTYPE_GRGB
6090 POLYTYPE_ATEX
6091 POLYTYPE_PTEX
6092 POLYTYPE_ATEX_MASK
6093 POLYTYPE_PTEX_MASK
6094 POLYTYPE_ATEX_LIT
6095 POLYTYPE_PTEX_LIT
6096 POLYTYPE_ATEX_MASK_LIT
6097 POLYTYPE_PTEX_MASK_LIT
6098 POLYTYPE_ATEX_TRANS
6099 POLYTYPE_PTEX_TRANS
6100 POLYTYPE_ATEX_MASK_TRANS
6101 POLYTYPE_PTEX_MASK_TRANS
6102 */
6103
6104 if(mustDestroyBmp)
6105 destroy_bitmap(tex);
6106
6107 }
6108
6109
6110 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6111 {
6112 //sdci[1]=layer
6113 //sdci[2]=x1
6114 //sdci[3]=y1
6115
6116 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6117 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6118 {
6119 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6120 return;
6121 }
6122 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
6123 if ( refbmp == NULL ) return;
6124
6125
6126 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6127
6128 int32_t x1 = sdci[2]/10000;
6129 int32_t y1 = (sdci[3]/10000)+yoffset;
6130 int32_t col = getpixel(refbmp, x1, y1);
6131 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6132 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[DRAWCMD_BMP_TARGET]));
6133 FFCore.set_sarg1(col);
6134 }
6135
6136
6137
6138
6139 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6140 {
6141 //sdci[1]=layer
6142 //sdci[2]=x1
6143 //sdci[3]=y1
6144 //sdci[4]=x2
6145 //sdci[5]=y2
6146 //sdci[6]=x3
6147 //sdci[7]=y3
6148 //sdci[8]=width
6149 //sdci[9]=height
6150 //sdci[10]=cset
6151 //sdci[11]=flip
6152 //sdci[12]=tile/combo
6153 //sdci[13]=polytype
6154 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6155 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6156 {
6157 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6158 return;
6159 }
6160 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
6161 if ( refbmp == NULL ) return;
6162
6163
6164 int32_t render_source = sdci[14];
6165 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6166
6167 bool tex_is_bitmap = ( sdci[14] != 0 );
6168
6169 BITMAP *bmptexture=NULL;
6170 if ( tex_is_bitmap )
6171 {
6172 bmptexture = resolveScriptingBitmap(render_source);
6173 if ( !bmptexture )
6174 {
6175 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6176 tex_is_bitmap = 0;
6177 }
6178 }
6179
6180 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6181
6182 int32_t x1 = sdci[2]/10000;
6183 int32_t y1 = sdci[3]/10000;
6184 int32_t x2 = sdci[4]/10000;
6185 int32_t y2 = sdci[5]/10000;
6186 int32_t x3 = sdci[6]/10000;
6187 int32_t y3 = sdci[7]/10000;
6188 int32_t w = sdci[8]/10000;
6189 int32_t h = sdci[9]/10000;
6190 int32_t color = sdci[10]/10000;
6191 int32_t flip=(sdci[11]/10000)&3;
6192 int32_t tile = sdci[12]/10000;
6193 int32_t polytype = sdci[13]/10000;
6194
6195 polytype = vbound(polytype, 0, 14);
6196 int32_t utex_w = w;
6197 int32_t utex_h = h;
6198
6199
6200 int32_t tex_width = w*16;
6201 int32_t tex_height = h*16;
6202
6203 bool mustDestroyBmp = false;
6204 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6205
6206 if(!tex)
6207 {
6208 mustDestroyBmp = true;
6209 tex = create_bitmap_ex(8, tex_width, tex_height);
6210 clear_bitmap(tex);
6211 }
6212
6213 int32_t col[3];
6214 /*
6215 if( color < 0 )
6216 {
6217 col[0]=draw_container.color_buffer[0];
6218 col[1]=draw_container.color_buffer[1];
6219 col[2]=draw_container.color_buffer[2];
6220 }
6221 else */
6222 {
6223 col[0]=col[1]=col[2]=color;
6224 }
6225
6226 if(tile > 0) // TILE
6227 {
6228 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6229 }
6230 else // COMBO
6231 {
6232 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
6233 const int32_t tiletodraw = combo_tile(c, x1, y1);
6234 flip = flip ^ c.flip;
6235
6236 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6237 }
6238 if ( !tex_is_bitmap )
6239 {
6240 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6241 {
6242 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6243 return; //non power of two error
6244 }
6245 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6246 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6247 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6248
6249
6250 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6251
6252 }
6253
6254 else
6255 {
6256 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6257 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6258 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6259 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6260
6261 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6262 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6263 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6264
6265
6266 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6267
6268 }
6269
6270 if(mustDestroyBmp)
6271 destroy_bitmap(tex);
6272 }
6273
6274
6275 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6276 {
6277 /*
6278 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6279 int32_t scale_x, int32_t scale_y){
6280
6281 //sdci[1]=layer
6282 //sdci[2]=bitmap target
6283 //
6284 // -2 is the current Render Target
6285 // -1, this is the screen (framebuf).
6286 // 0: Render target 0
6287 // 1: Render target 1
6288 // 2: Render target 2
6289 // 3: Render target 3
6290 // 4: Render target 4
6291 // 5: Render target 5
6292 // 6: Render target 6
6293 // Otherwise: The pointer to a bitmap.
6294
6295 //sdci[3]=sourcex
6296 //sdci[4]=sourcey
6297 //sdci[5]=sourcew
6298 //sdci[6]=sourceh
6299
6300 //sdci[7]=destw
6301 //sdci[8]=desth
6302 //sdci[9]=angle
6303 //scdi[10] = pivot cx
6304 //sdci[11] = pivot cy
6305 //sdci[12] = space Z
6306 //sdci[13] = horizon
6307 //scdi[14] = scale X
6308 //scdi[15] = scale Y
6309 //sdci[16] = masked?
6310 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6311
6312
6313
6314 // ZScript-side constant values:
6315 const int32_t BITDX_NORMAL = 0;
6316 const int32_t BITDX_TRANS = 1; //Translucent
6317 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6318 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6319 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6320 //Note: Some modes cannot be combined. if a combination is not supported, an error
6321 // detailing this will be shown in allegro.log.
6322
6323 //scdi[15] = litcolour
6324 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6325 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6326
6327 //sdci[16]=mask
6328
6329 */
6330
6331
6332 int32_t bitmapIndex = sdci[2];
6333 int32_t usr_bitmap_index = sdci[2];
6334 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6335 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6336
6337 if ( bitmapIndex >= 10000 )
6338 {
6339 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6340 }
6341 else if ( usr_bitmap_index > 0 )
6342 {
6343 bitmapIndex = usr_bitmap_index;
6344 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6345 yoffset = 0;
6346 }
6347
6348 //rendering mode 7 args
6349 double srcX = sdci[3]/10000.0;
6350 double srcY = sdci[4]/10000.0;
6351 double destX = sdci[5]/10000.0;
6352 double destY = sdci[6]/10000.0;
6353
6354 double destW = sdci[7]/10000.0;
6355 double destH = sdci[8]/10000.0;
6356 double space_z = sdci[9]/10000.0;
6357 double horizon = sdci[10]/10000.0;
6358 double scale_x = sdci[11]/10000.0;
6359 double scale_y = sdci[12]/10000.0;
6360 byte masked = ( sdci[13] ) ? 1 : 0;
6361
6362
6363 int32_t ref = 0;
6364
6365 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6366 //Do we need to also check the render target and do the same thing if the
6367 //dest == -2 and the render target is not RT_SCREEN?
6368
6369 ref = sdci[DRAWCMD_BMP_TARGET];
6370
6371
6372 if ( ref <= 0 )
6373 {
6374 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6375 return;
6376 }
6377 BITMAP *sourceBitmap = resolveScriptingBitmap(ref); //This can be the screen, as -1.
6378
6379 if(!sourceBitmap)
6380 {
6381 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6382 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6383 return;
6384 }
6385
6386 BITMAP *destBMP=NULL;
6387 switch(bitmapIndex)
6388 {
6389 // Current render target (RT_CURRENT).
6390 // This is the only reason we aren't using resolveScriptingBitmap for the target bitmap. All the other cases should be equivalent.
6391 case -2:
6392 {
6393 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6394 if ( curr_rt >= 0 && curr_rt < 7 )
6395 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6396 else destBMP = bmp; //screen
6397 break;
6398 }
6399 case -1:
6400 destBMP = bmp; //this is framebuf, by default
6401 break;
6402
6403 //1 through 6 are the old system bitmaps (Render Targets)
6404 case 0:
6405 case 1:
6406 case 2:
6407 case 3:
6408 case 4:
6409 case 5:
6410 case 6:
6411 {
6412 //This gets a render target.
6413 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6414 break;
6415 }
6416 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6417 default:
6418 {
6419 auto& usr_bitmap = scb.get(usr_bitmap_index);
6420 destBMP = usr_bitmap.u_bmp;
6421 if ( !usr_bitmap.u_bmp )
6422 {
6423 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6424 break;
6425 }
6426 }
6427 }
6428
6429 if (!destBMP)
6430 {
6431 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6432 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6433 return;
6434 }
6435
6436 //dx = dx + xoffset; //don't do this here!
6437 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6438 //All of these are a factor of 10000 as fix.
6439 int32_t screen_x = 0; int32_t screen_y = 0;
6440
6441 double distance = 0; double horizontal_scale = 0;
6442
6443 int32_t screen_y_horizon = 0;
6444
6445 double line_dx = 0; double line_dy = 0;
6446
6447 int32_t space_x = 0; int32_t space_y = 0;
6448
6449 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6450 {
6451 //Calculate the distance of each line from the camera point
6452 screen_y_horizon = screen_y + horizon;
6453
6454 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6455
6456 //Get the scale of each line based on the distance
6457
6458 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6459
6460 //There was some math here before I stripped out the rotation step
6461 line_dx = horizontal_scale;
6462 line_dy = 0;
6463
6464 //space_x,space_y - where to grab each scanline from on the space bitmap
6465 space_x = srcX - destW/2.0 * line_dx;
6466 space_y = srcY - distance + destH/2.0 * line_dy;
6467
6468 //Keep blits within the bounds of both bitmaps to avoid crashes
6469 int32_t y1 = srcY+space_y;
6470 int32_t y2 = destY+screen_y;
6471 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6472 {
6473 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6474 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6475 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6476 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6477 }
6478 }
6479 }
6480
6481
6482 //Draw]()
6483 265749 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6484 {
6485 /*
6486 //sdci[1]=layer
6487 //sdci[2]=bitmap target
6488 //
6489 // -2 is the current Render Target
6490 // -1, this is the screen (framebuf).
6491 // 0: Render target 0
6492 // 1: Render target 1
6493 // 2: Render target 2
6494 // 3: Render target 3
6495 // 4: Render target 4
6496 // 5: Render target 5
6497 // 6: Render target 6
6498 // Otherwise: The pointer to a bitmap.
6499
6500 //sdci[3]=sourcex
6501 //sdci[4]=sourcey
6502 //sdci[5]=sourcew
6503 //sdci[6]=sourceh
6504 //sdci[7]=destx
6505 //sdci[8]=desty
6506 //sdci[9]=destw
6507 //sdci[10]=desth
6508 //sdci[11]=rotation/angle
6509 //scdi[12] = pivot cx
6510 //sdci[13] = pivot cy
6511 //scdi[14] = effect flags
6512 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6513
6514 // ZScript-side constant values:
6515 const int32_t BITDX_NORMAL = 0;
6516 const int32_t BITDX_TRANS = 1; //Translucent
6517 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6518 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6519 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6520 //Note: Some modes cannot be combined. if a combination is not supported, an error
6521 // detailing this will be shown in allegro.log.
6522
6523 //scdi[15] = litcolour
6524 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6525 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6526
6527 //sdci[16]=mask
6528
6529 */
6530
6531 265749 int32_t usr_bitmap_index = sdci[2];
6532 531498 auto [bitmapIndex, is_user_bitmap] = resolveScriptingBitmapId(usr_bitmap_index);
6533
6534
6535 265749 int32_t sx = sdci[3]/10000;
6536 265749 int32_t sy = sdci[4]/10000;
6537 265749 int32_t sw = sdci[5]/10000;
6538 265749 int32_t sh = sdci[6]/10000;
6539 265749 int32_t dx = sdci[7]/10000;
6540 265749 int32_t dy = sdci[8]/10000;
6541 265749 int32_t dw = sdci[9]/10000;
6542 265749 int32_t dh = sdci[10]/10000;
6543 265749 float rot = sdci[11]/10000;
6544 265749 int32_t cx = sdci[12]/10000;
6545 265749 int32_t cy = sdci[13]/10000;
6546 265749 int32_t mode = sdci[14]/10000;
6547 265749 int32_t litcolour = sdci[15]/10000;
6548 265749 bool masked = (sdci[16] != 0);
6549
6550 265749 int32_t ref = 0;
6551
6552
2/2
✓ Branch 0 taken 265389 times.
✓ Branch 1 taken 360 times.
265749 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
6553 {
6554
2/2
✓ Branch 0 taken 93046 times.
✓ Branch 1 taken 172343 times.
265389 if (is_user_bitmap)
6555 172343 yoffset = 0;
6556
6557 265389 dx += xoffset;
6558 265389 dy += yoffset;
6559 265389 }
6560 else
6561 {
6562 360 dx += secondary_draw_origin_xoff;
6563 360 dy += secondary_draw_origin_yoff;
6564
6565 360 sx += xoffset;
6566 360 sy += yoffset;
6567 }
6568
6569 265749 ref = sdci[DRAWCMD_BMP_TARGET];
6570
6571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 265749 times.
265749 if ( ref <= 0 )
6572 {
6573 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6574 return;
6575 }
6576 265749 BITMAP *sourceBitmap = resolveScriptingBitmap(ref); //This can be the screen, as -1.
6577
6578
1/2
✓ Branch 0 taken 265749 times.
✗ Branch 1 not taken.
265749 if(!sourceBitmap)
6579 {
6580
6581 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6582 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6583 return;
6584 }
6585
6586 265749 BITMAP *destBMP=NULL;
6587
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172343 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 92620 times.
265749 switch(bitmapIndex)
6588 {
6589 // Current render target (RT_CURRENT).
6590 // This is the only reason we aren't using resolveScriptingBitmap for the target bitmap. All the other cases should be equivalent.
6591 case -2:
6592 {
6593 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6594
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6595 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6596 786 else destBMP = bmp; //screen
6597 786 break;
6598 }
6599 case -1:
6600 92620 destBMP = bmp; //this is framebuf, by default
6601 92620 break;
6602 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6603 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6604 //destBMP = framebuf; //Drawing to the screen.
6605 //break;
6606
6607 //1 through 6 are the old system bitmaps (Render Targets)
6608 case 0:
6609 case 1:
6610 case 2:
6611 case 3:
6612 case 4:
6613 case 5:
6614 case 6:
6615 {
6616 //This gets a render target.
6617 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6618
6619 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6620 //sdci[18] = bitmapIndex;
6621 break;
6622 }
6623 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6624 default:
6625 {
6626 172343 auto& usr_bitmap = scb.get(usr_bitmap_index);
6627 172343 destBMP = usr_bitmap.u_bmp;
6628 //sdci[18] = usr_bitmap_index;
6629
1/2
✓ Branch 0 taken 172343 times.
✗ Branch 1 not taken.
172343 if ( !usr_bitmap.u_bmp )
6630 {
6631 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6632 break;
6633 }
6634 }
6635 172343 }
6636
6637
1/2
✓ Branch 0 taken 265749 times.
✗ Branch 1 not taken.
265749 if (!destBMP)
6638 {
6639 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6640 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6641 return;
6642 }
6643
6644
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 264722 times.
265749 bool stretched = (sw != dw || sh != dh);
6645 265749 BITMAP* subBmp = 0;
6646
6647
4/4
✓ Branch 0 taken 264170 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24983 times.
✓ Branch 3 taken 239187 times.
265749 if(rot != 0 || mode != 0)
6648 {
6649 26562 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6650 26562 clear_bitmap(subBmp);
6651
6652
1/2
✓ Branch 0 taken 26562 times.
✗ Branch 1 not taken.
26562 if(!subBmp)
6653 {
6654
6655 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6656 return;
6657 }
6658 26562 }
6659 265749 BITMAP* sbmp = sourceBitmap;
6660
2/4
✓ Branch 0 taken 265749 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 265749 times.
265749 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6661 {
6662 sbmp = create_bitmap_ex(8, sw, sh);
6663 clear_bitmap(sbmp);
6664 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6665 sx = 0;
6666 sy = 0;
6667 }
6668 //dx = dx + xoffset; //don't do this here!
6669 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6670
6671
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 264147 times.
265749 if(stretched)
6672 {
6673
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6674 { //stretched and masked
6675
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6676 { //if not rotated
6677
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6678 {
6679 case 1:
6680 //transparent
6681 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6682 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6683 900 break;
6684
6685
6686 case 2:
6687 //pivot?
6688 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6689 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6690 //Pivoting requires two more args
6691 break;
6692
6693 case 3:
6694 //pivot + trans
6695 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6696 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6697 break;
6698
6699 case 4:
6700 //flip v
6701 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6702 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6703 break;
6704
6705 case 5:
6706 //trans + v flip
6707 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6708 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6709 break;
6710
6711 case 6:
6712 //pivot + v flip
6713 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6714 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6715 break;
6716
6717 case 8:
6718 //vlip h
6719 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6720 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6721 break;
6722
6723 case 9:
6724 //trans + h flip
6725 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6726 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6727 break;
6728
6729 case 10:
6730 //flip H and pivot
6731 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6732 //return error cannot pivot and h flip
6733 break;
6734
6735 case 12:
6736 //vh flip
6737 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6738 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6739 break;
6740
6741 case 13:
6742 //trans + vh flip
6743 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6744 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6745 break;
6746
6747 case 14:
6748 //pivot and vh flip
6749 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6750 //return error cannot both pivot and vh flip
6751 break;
6752
6753 case 16:
6754 //lit
6755 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6756 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6757 break;
6758
6759 case 18:
6760 //pivot, lit
6761 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6762 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6763 break;
6764
6765 case 20:
6766 //lit + v flip
6767 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6768 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6769 break;
6770
6771 case 22:
6772 //Pivot, vflip, lit
6773 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6774 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6775 break;
6776
6777 case 24:
6778 //lit + h flip
6779 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6780 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6781 break;
6782
6783 case 26:
6784 //pivot + lit + hflip
6785 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6786 //return error cannot pivot, lit, and flip
6787 break;
6788
6789 case 28:
6790 //lit + vh flip
6791 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6792 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6793 break;
6794
6795 case 32: //gouraud
6796 //Probably not wort supporting.
6797 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6798 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6799 break;
6800
6801 case 0:
6802 //no effect
6803 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6804 1 break;
6805
6806
6807 default:
6808
6809 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6810
6811
6812 }
6813 901 } //end if not rotated
6814
6815
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6816 {
6817
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6818 {
6819 case 1:
6820 //transparent
6821 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6822 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6823
6824 break;
6825
6826 case 2:
6827 //pivot?
6828 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6829 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6830 //Pivoting requires two more args
6831 break;
6832
6833 case 3:
6834 //pivot + trans
6835 //return an error, cannot both rotate and pivot
6836 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6837 break;
6838
6839 case 4:
6840 //flip v
6841 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6842 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6843 break;
6844
6845 case 5:
6846 //trans + v flip
6847 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6848 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6849 break;
6850
6851 case 6:
6852 //pivot + v flip
6853 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6854 //return an error, cannot both rotate and pivot
6855 break;
6856
6857 case 8:
6858 //flip h
6859 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6860 //return an error, cannot both rotate and flip H
6861 break;
6862
6863 case 9:
6864 //trans + h flip
6865 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6866 //return an error, cannot rotate and flip a trans sprite
6867 break;
6868
6869 case 10:
6870 //flip H and pivot
6871 //return error cannot pivot and h flip
6872 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6873 break;
6874
6875 case 12:
6876 //vh flip
6877 //return an error, cannot rotate and VH flip a trans sprite
6878 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6879 break;
6880
6881 case 13:
6882 //trans + vh flip
6883 //return an error, cannot rotate and VH flip a trans sprite
6884 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6885 break;
6886
6887 case 14:
6888 //pivot and vh flip
6889 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6890 //return error cannot both pivot and vh flip
6891 break;
6892
6893 case 16:
6894 //lit
6895 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6896 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6897 break;
6898
6899 case 18:
6900 //pivot, lit
6901 //return an error, cannot both rotate and pivot
6902 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6903 break;
6904
6905 case 20:
6906 //lit + vflip
6907 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6908 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6909 break;
6910
6911 case 22:
6912 //Pivot, vflip, lit
6913 //return an error, cannot both rotate and pivot
6914 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6915 break;
6916
6917 case 24:
6918 //lit + h flip
6919 //return an error, cannot both rotate and H flip
6920 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6921 break;
6922
6923 case 26:
6924 //pivot + lit + hflip
6925 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6926 //return error cannot pivot, lit, and flip
6927 break;
6928
6929 case 28:
6930 //lit + vh flip
6931 //return an error, cannot both rotate and VH flip
6932 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6933 break;
6934
6935 case 32: //gouraud
6936 //Probably not wort supporting.
6937 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6938 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6939 break;
6940
6941 case 0:
6942 //no effect.
6943 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6944 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6945 574 break;
6946
6947 default:
6948
6949 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6950
6951 }
6952 574 }
6953 1475 } //end if stretched and masked
6954
6955 else //stretched, not masked
6956 {
6957
6958
6959
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
6960 {
6961
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
6962 {
6963 case 1:
6964 //transparent
6965 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6966 draw_trans_sprite(destBMP, subBmp, dx, dy);
6967 break;
6968
6969
6970 case 2:
6971 //pivot?
6972 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6973 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6974 //Pivoting requires two more args
6975 break;
6976
6977 case 3:
6978 //pivot + trans
6979 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6980 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
6981 break;
6982
6983 case 4:
6984 //flip v
6985 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6986 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6987 break;
6988
6989 case 5:
6990 //trans + v flip
6991 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6992 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6993 break;
6994
6995 case 6:
6996 //pivot + v flip
6997 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6998 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6999 break;
7000
7001 case 8:
7002 //vlip h
7003 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7004 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7005 break;
7006
7007 case 9:
7008 //trans + h flip
7009 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7010 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7011 break;
7012
7013 case 10:
7014 //flip H and pivot
7015 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7016 //return error cannot pivot and h flip
7017 break;
7018
7019 case 12:
7020 //vh flip
7021 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7022 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7023 break;
7024
7025 case 13:
7026 //trans + vh flip
7027 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7028 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7029 break;
7030
7031 case 14:
7032 //pivot and vh flip
7033 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7034 //return error cannot both pivot and vh flip
7035 break;
7036
7037 case 16:
7038 //lit
7039 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7040 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7041 break;
7042
7043 case 18:
7044 //pivot, lit
7045 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7046 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7047 break;
7048
7049 case 20:
7050 //lit + v flip
7051 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7052 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7053 break;
7054
7055 case 22:
7056 //Pivot, vflip, lit
7057 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7058 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7059 break;
7060
7061 case 24:
7062 //lit + h flip
7063 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7064 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7065 break;
7066
7067 case 26:
7068 //pivot + lit + hflip
7069 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7070 //return error cannot pivot, lit, and flip
7071 break;
7072
7073 case 28:
7074 //lit + vh flip
7075 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7076 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7077 break;
7078
7079 case 32: //gouraud
7080 //Probably not wort supporting.
7081 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7082 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7083 break;
7084
7085 case 0:
7086 //no effect
7087 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7088 127 break;
7089
7090
7091 default:
7092
7093 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7094
7095
7096 }
7097 127 } //end if not rotated
7098
7099
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7100 {
7101 switch(mode)
7102 {
7103 case 1:
7104 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7105 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7106
7107 break;
7108
7109 case 2:
7110 //pivot?
7111 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7112 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7113 //Pivoting requires two more args
7114 break;
7115
7116 case 3:
7117 //pivot + trans
7118 //return an error, cannot both rotate and pivot
7119 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7120 break;
7121
7122 case 4:
7123 //flip v
7124 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7125 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7126 break;
7127
7128 case 5:
7129 //trans + v flip
7130 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7131 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7132 break;
7133
7134 case 6:
7135 //pivot + v flip
7136 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7137 //return an error, cannot both rotate and pivot
7138 break;
7139
7140 case 8:
7141 //flip h
7142 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7143 //return an error, cannot both rotate and flip H
7144 break;
7145
7146 case 9:
7147 //trans + h flip
7148 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7149 //return an error, cannot rotate and flip a trans sprite
7150 break;
7151
7152 case 10:
7153 //flip H and pivot
7154 //return error cannot pivot and h flip
7155 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7156 break;
7157
7158 case 12:
7159 //vh flip
7160 //return an error, cannot rotate and VH flip a trans sprite
7161 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7162 break;
7163
7164 case 13:
7165 //trans + vh flip
7166 //return an error, cannot rotate and VH flip a trans sprite
7167 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7168 break;
7169
7170 case 14:
7171 //pivot and vh flip
7172 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7173 //return error cannot both pivot and vh flip
7174 break;
7175
7176 case 16:
7177 //lit
7178 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7179 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7180 break;
7181
7182 case 18:
7183 //pivot, lit
7184 //return an error, cannot both rotate and pivot
7185 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7186 break;
7187
7188 case 20:
7189 //lit + vflip
7190 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7191 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7192 break;
7193
7194 case 22:
7195 //Pivot, vflip, lit
7196 //return an error, cannot both rotate and pivot
7197 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7198 break;
7199
7200 case 24:
7201 //lit + h flip
7202 //return an error, cannot both rotate and H flip
7203 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7204 break;
7205
7206 case 26:
7207 //pivot + lit + hflip
7208 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7209 //return error cannot pivot, lit, and flip
7210 break;
7211
7212 case 28:
7213 //lit + vh flip
7214 //return an error, cannot both rotate and VH flip
7215 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7216 break;
7217
7218 case 32: //gouraud
7219 //Probably not wort supporting.
7220 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7221 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7222 break;
7223
7224 case 0:
7225 //no effect.
7226 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7227 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7228 break;
7229
7230 default:
7231
7232 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7233
7234 }
7235 }
7236
7237 } //end if stretched, but not masked
7238 1602 }
7239 else //not stretched
7240 {
7241
7242
2/2
✓ Branch 0 taken 253164 times.
✓ Branch 1 taken 10983 times.
264147 if(masked) //if masked, but not stretched
7243 {
7244
7245
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 252159 times.
253164 if ( rot == 0 ) //if not rotated
7246 {
7247
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 233470 times.
252159 switch(mode)
7248 {
7249 case 1:
7250 //transparent
7251 18689 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7252 18689 draw_trans_sprite(destBMP, subBmp, dx, dy);
7253 18689 break;
7254
7255
7256 case 2:
7257 //pivot?
7258 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7259 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7260 //Pivoting requires two more args
7261 break;
7262
7263 case 3:
7264 //pivot + trans
7265 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7266 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7267 break;
7268
7269 case 4:
7270 //flip v
7271 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7272 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7273 break;
7274
7275 case 5:
7276 //trans + v flip
7277 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7278 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7279 break;
7280
7281 case 6:
7282 //pivot + v flip
7283 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7284 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7285 break;
7286
7287 case 8:
7288 //vlip h
7289 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7290 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7291 break;
7292
7293 case 9:
7294 //trans + h flip
7295 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7296 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7297 break;
7298
7299 case 10:
7300 //flip H and pivot
7301 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7302 //return error cannot pivot and h flip
7303 break;
7304
7305 case 12:
7306 //vh flip
7307 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7308 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7309 break;
7310
7311 case 13:
7312 //trans + vh flip
7313 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7314 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7315 break;
7316
7317 case 14:
7318 //pivot and vh flip
7319 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7320 //return error cannot both pivot and vh flip
7321 break;
7322
7323 case 16:
7324 //lit
7325 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7326 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7327 break;
7328
7329 case 18:
7330 //pivot, lit
7331 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7332 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7333 break;
7334
7335 case 20:
7336 //lit + v flip
7337 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7338 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7339 break;
7340
7341 case 22:
7342 //Pivot, vflip, lit
7343 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7344 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7345 break;
7346
7347 case 24:
7348 //lit + h flip
7349 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7350 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7351 break;
7352
7353 case 26:
7354 //pivot + lit + hflip
7355 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7356 //return error cannot pivot, lit, and flip
7357 break;
7358
7359 case 28:
7360 //lit + vh flip
7361 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7362 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7363 break;
7364
7365 case 32: //gouraud
7366 //Probably not wort supporting.
7367 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7368 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7369 break;
7370
7371 case 0:
7372 //no effect
7373 233470 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7374 233470 break;
7375
7376
7377 default:
7378
7379 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7380
7381
7382 }
7383 252159 } //end if not rotated
7384
7385
2/2
✓ Branch 0 taken 252159 times.
✓ Branch 1 taken 1005 times.
253164 if ( rot != 0 ) //if rotated
7386 {
7387
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7388 {
7389 case 1:
7390 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7391 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7392
7393 break;
7394
7395 case 2:
7396 //pivot?
7397 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7398 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7399 //Pivoting requires two more args
7400 break;
7401
7402 case 3:
7403 //pivot + trans
7404 //return an error, cannot both rotate and pivot
7405 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7406 break;
7407
7408 case 4:
7409 //flip v
7410 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7411 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7412 break;
7413
7414 case 5:
7415 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7416 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7417 break;
7418
7419 case 6:
7420 //pivot + v flip
7421 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7422 //return an error, cannot both rotate and pivot
7423 break;
7424
7425 case 8:
7426 //flip h
7427 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7428 //return an error, cannot both rotate and flip H
7429 break;
7430
7431 case 9:
7432 //trans + h flip
7433 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7434 //return an error, cannot rotate and flip a trans sprite
7435 break;
7436
7437 case 10:
7438 //flip H and pivot
7439 //return error cannot pivot and h flip
7440 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7441 break;
7442
7443 case 12:
7444 //vh flip
7445 //return an error, cannot rotate and VH flip a trans sprite
7446 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7447 break;
7448
7449 case 13:
7450 //trans + vh flip
7451 //return an error, cannot rotate and VH flip a trans sprite
7452 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7453 break;
7454
7455 case 14:
7456 //pivot and vh flip
7457 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7458 //return error cannot both pivot and vh flip
7459 break;
7460
7461 case 16:
7462 //lit
7463 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7464 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7465 break;
7466
7467 case 18:
7468 //pivot, lit
7469 //return an error, cannot both rotate and pivot
7470 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7471 break;
7472
7473 case 20:
7474 //lit + vflip
7475 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7476 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7477 break;
7478
7479 case 22:
7480 //Pivot, vflip, lit
7481 //return an error, cannot both rotate and pivot
7482 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7483 break;
7484
7485 case 24:
7486 //lit + h flip
7487 //return an error, cannot both rotate and H flip
7488 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7489 break;
7490
7491 case 26:
7492 //pivot + lit + hflip
7493 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7494 //return error cannot pivot, lit, and flip
7495 break;
7496
7497 case 28:
7498 //lit + vh flip
7499 //return an error, cannot both rotate and VH flip
7500 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7501 break;
7502
7503 case 32: //gouraud
7504 //Probably not wort supporting.
7505 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7506 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7507 break;
7508
7509 case 0:
7510 //no effect.
7511 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7512 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7513 1005 break;
7514
7515 default:
7516
7517 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7518
7519 }
7520 1005 } //end rtated, masked
7521 253164 } //end if masked
7522
7523 else //not masked, and not stretched; just blit
7524 {
7525
7526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10983 times.
10983 if ( rot == 0 ) //if not rotated
7527 {
7528
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5589 times.
10983 switch(mode)
7529 {
7530 case 1:
7531 //transparent
7532 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7533 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7534 5394 break;
7535
7536
7537 case 2:
7538 //pivot?
7539 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7540 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7541 //Pivoting requires two more args
7542 break;
7543
7544 case 3:
7545 //pivot + trans
7546 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7547 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7548 break;
7549
7550 case 4:
7551 //flip v
7552 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7553 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7554 break;
7555
7556 case 5:
7557 //trans + v flip
7558 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7559 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7560 break;
7561
7562 case 6:
7563 //pivot + v flip
7564 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7565 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7566 break;
7567
7568 case 8:
7569 //vlip h
7570 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7571 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7572 break;
7573
7574 case 9:
7575 //trans + h flip
7576 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7577 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7578 break;
7579
7580 case 10:
7581 //flip H and pivot
7582 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7583 //return error cannot pivot and h flip
7584 break;
7585
7586 case 12:
7587 //vh flip
7588 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7589 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7590 break;
7591
7592 case 13:
7593 //trans + vh flip
7594 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7595 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7596 break;
7597
7598 case 14:
7599 //pivot and vh flip
7600 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7601 //return error cannot both pivot and vh flip
7602 break;
7603
7604 case 16:
7605 //lit
7606 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7607 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7608 break;
7609
7610 case 18:
7611 //pivot, lit
7612 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7613 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7614 break;
7615
7616 case 20:
7617 //lit + v flip
7618 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7619 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7620 break;
7621
7622 case 22:
7623 //Pivot, vflip, lit
7624 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7625 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7626 break;
7627
7628 case 24:
7629 //lit + h flip
7630 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7631 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7632 break;
7633
7634 case 26:
7635 //pivot + lit + hflip
7636 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7637 //return error cannot pivot, lit, and flip
7638 break;
7639
7640 case 28:
7641 //lit + vh flip
7642 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7643 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7644 break;
7645
7646 case 32: //gouraud
7647 //Probably not wort supporting.
7648 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7649 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7650 break;
7651
7652 case 0:
7653 //no effect
7654 5589 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7655 5589 break;
7656
7657
7658 default:
7659
7660 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7661
7662
7663 }
7664 10983 } //end if not rotated
7665
7666
1/2
✓ Branch 0 taken 10983 times.
✗ Branch 1 not taken.
10983 if ( rot != 0 ) //if rotated
7667 {
7668 switch(mode)
7669 {
7670 case 1:
7671 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7672 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7673
7674 break;
7675
7676 case 2:
7677 //pivot?
7678 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7679 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7680 //Pivoting requires two more args
7681 break;
7682
7683 case 3:
7684 //pivot + trans
7685 //return an error, cannot both rotate and pivot
7686 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7687 break;
7688
7689 case 4:
7690 //flip v
7691 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7692 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7693 break;
7694
7695 case 5:
7696 //trans + v flip
7697 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7698 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7699 break;
7700
7701 case 6:
7702 //pivot + v flip
7703 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7704 //return an error, cannot both rotate and pivot
7705 break;
7706
7707 case 8:
7708 //flip h
7709 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7710 //return an error, cannot both rotate and flip H
7711 break;
7712
7713 case 9:
7714 //trans + h flip
7715 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7716 //return an error, cannot rotate and flip a trans sprite
7717 break;
7718
7719 case 10:
7720 //flip H and pivot
7721 //return error cannot pivot and h flip
7722 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7723 break;
7724
7725 case 12:
7726 //vh flip
7727 //return an error, cannot rotate and VH flip a trans sprite
7728 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7729 break;
7730
7731 case 13:
7732 //trans + vh flip
7733 //return an error, cannot rotate and VH flip a trans sprite
7734 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7735 break;
7736
7737 case 14:
7738 //pivot and vh flip
7739 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7740 //return error cannot both pivot and vh flip
7741 break;
7742
7743 case 16:
7744 //lit
7745 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7746 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7747 break;
7748
7749 case 18:
7750 //pivot, lit
7751 //return an error, cannot both rotate and pivot
7752 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7753 break;
7754
7755 case 20:
7756 //lit + vflip
7757 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7758 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7759 break;
7760
7761 case 22:
7762 //Pivot, vflip, lit
7763 //return an error, cannot both rotate and pivot
7764 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7765 break;
7766
7767 case 24:
7768 //lit + h flip
7769 //return an error, cannot both rotate and H flip
7770 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7771 break;
7772
7773 case 26:
7774 //pivot + lit + hflip
7775 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7776 //return error cannot pivot, lit, and flip
7777 break;
7778
7779 case 28:
7780 //lit + vh flip
7781 //return an error, cannot both rotate and VH flip
7782 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7783 break;
7784
7785 case 32: //gouraud
7786 //Probably not wort supporting.
7787 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7788 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7789 break;
7790
7791 case 0:
7792 //no effect.
7793 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7794 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7795 break;
7796
7797 default:
7798
7799 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7800
7801 }
7802 } //end if rotated
7803 } //end if not masked
7804 } //end if not stretched
7805
7806 //cleanup
7807
2/2
✓ Branch 0 taken 26562 times.
✓ Branch 1 taken 239187 times.
265749 if(subBmp)
7808 {
7809 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7810 26562 destroy_bitmap(subBmp);
7811 26562 }
7812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 265749 times.
265749 if (sbmp != sourceBitmap)
7813 {
7814 destroy_bitmap(sbmp);
7815 }
7816 265749 }
7817
7818
7819
7820 113329 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7821 {
7822 /*
7823 //sdci[1]=layer
7824 //sdci[2]=bitmap target
7825 //
7826 // -2 is the current Render Target
7827 // -1, this is the screen (framebuf).
7828 // 0: Render target 0
7829 // 1: Render target 1
7830 // 2: Render target 2
7831 // 3: Render target 3
7832 // 4: Render target 4
7833 // 5: Render target 5
7834 // 6: Render target 6
7835 // Otherwise: The pointer to a bitmap.
7836
7837 //sdci[3]=sourcex
7838 //sdci[4]=sourcey
7839 //sdci[5]=sourcew
7840 //sdci[6]=sourceh
7841 //sdci[7]=destx
7842 //sdci[8]=desty
7843 //sdci[9]=destw
7844 //sdci[10]=desth
7845 //sdci[11]=rotation/angle
7846 //scdi[12] = pivot cx
7847 //sdci[13] = pivot cy
7848 //scdi[14] = effect flags
7849 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
7850
7851 // ZScript-side constant values:
7852 const int32_t BITDX_NORMAL = 0;
7853 const int32_t BITDX_TRANS = 1; //Translucent
7854 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7855 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7856 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7857 //Note: Some modes cannot be combined. if a combination is not supported, an error
7858 // detailing this will be shown in allegro.log.
7859
7860 //scdi[15] = litcolour
7861 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7862 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7863
7864 //sdci[16]=mask
7865
7866 */
7867
7868 113329 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7869
7870 113329 int32_t usr_bitmap_index = sdci[2];
7871 339987 auto [bitmapIndex, is_user_bitmap] = resolveScriptingBitmapId(usr_bitmap_index);
7872
7873 113329 int32_t sx = sdci[3]/10000;
7874 113329 int32_t sy = sdci[4]/10000;
7875 113329 int32_t sw = sdci[5]/10000;
7876 113329 int32_t sh = sdci[6]/10000;
7877 113329 int32_t dx = sdci[7]/10000;
7878 113329 int32_t dy = sdci[8]/10000;
7879 113329 int32_t dw = sdci[9]/10000;
7880 113329 int32_t dh = sdci[10]/10000;
7881 113329 float rot = sdci[11]/10000;
7882 113329 int32_t cx = sdci[12]/10000;
7883 113329 int32_t cy = sdci[13]/10000;
7884 113329 int32_t mode = sdci[14]/10000;
7885 113329 int32_t litcolour = sdci[15]/10000;
7886 113329 bool masked = (sdci[16] != 0);
7887
7888 113329 int32_t ref = 0;
7889
7890
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
7891 {
7892
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if (is_user_bitmap)
7893 113326 srcyoffset = 0;
7894
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
7895
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7896
7897 113329 dx += xoffset;
7898 113329 dy += yoffset;
7899
7900 113329 sx += srcxoffset;
7901 113329 sy += srcyoffset;
7902 113329 }
7903 else
7904 {
7905 dx += xoffset;
7906 dy += yoffset;
7907
7908 sx += secondary_draw_origin_xoff;
7909 sy += secondary_draw_origin_yoff;
7910 }
7911
7912 113329 ref = sdci[DRAWCMD_BMP_TARGET];
7913
7914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if ( ref <= 0 )
7915 {
7916 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7917 return;
7918 }
7919 113329 BITMAP *sourceBitmap = resolveScriptingBitmap(ref); //This can be the screen, as -1.
7920
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if(!sourceBitmap)
7921 {
7922 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
7923 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7924 return;
7925 }
7926
7927 113329 BITMAP *destBMP=NULL;
7928
7929
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
113329 switch(bitmapIndex)
7930 {
7931 // Current render target (RT_CURRENT).
7932 // This is the only reason we aren't using resolveScriptingBitmap for the target bitmap. All the other cases should be equivalent.
7933 case -2:
7934 {
7935 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
7936 if ( curr_rt >= 0 && curr_rt < 7 )
7937 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
7938 else destBMP = bmp; //screen
7939 break;
7940 }
7941 case -1:
7942 3 destBMP = bmp; //this is framebuf, by default
7943 3 break;
7944 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
7945 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
7946 //destBMP = framebuf; //Drawing to the screen.
7947 //break;
7948
7949 //1 through 6 are the old system bitmaps (Render Targets)
7950 case 0:
7951 case 1:
7952 case 2:
7953 case 3:
7954 case 4:
7955 case 5:
7956 case 6:
7957 {
7958 //This gets a render target.
7959 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
7960
7961 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
7962 //sdci[18] = bitmapIndex;
7963 break;
7964 }
7965 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
7966 default:
7967 {
7968 113326 auto& usr_bitmap = scb.get(usr_bitmap_index);
7969 113326 destBMP = usr_bitmap.u_bmp;
7970 //sdci[18] = usr_bitmap_index;
7971
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( !usr_bitmap.u_bmp )
7972 {
7973 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
7974 break;
7975 }
7976 }
7977 113326 }
7978
7979
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!destBMP)
7980 {
7981 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
7982 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7983 return;
7984 }
7985
7986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 bool stretched = (sw != dw || sh != dh);
7987
7988 113329 BITMAP* newDest = sourceBitmap;
7989 113329 BITMAP* newSource = destBMP; //Flip them.
7990
7991 113329 BITMAP* subBmp = 0;
7992
7993
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if(rot != 0 || mode != 0)
7994 {
7995 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
7996 clear_bitmap(subBmp);
7997
7998 if(!subBmp)
7999 {
8000 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
8001 return;
8002 }
8003 }
8004
8005
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
8006 {
8007 3 newSource = create_bitmap_ex(8, sw, sh);
8008 3 clear_bitmap(newSource);
8009 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
8010 3 sx = 0;
8011 3 sy = 0;
8012 3 }
8013 //dx = dx + xoffset; //don't do this here!
8014 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
8015
8016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(stretched)
8017 {
8018 if(masked)
8019 { //stretched and masked
8020 if ( rot == 0 )
8021 { //if not rotated
8022 switch(mode)
8023 {
8024 case 1:
8025 //transparent
8026 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8027 draw_trans_sprite(newDest, subBmp, dx, dy);
8028 break;
8029
8030
8031 case 2:
8032 //pivot?
8033 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8034 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8035 //Pivoting requires two more args
8036 break;
8037
8038 case 3:
8039 //pivot + trans
8040 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8041 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8042 break;
8043
8044 case 4:
8045 //flip v
8046 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8047 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8048 break;
8049
8050 case 5:
8051 //trans + v flip
8052 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8053 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8054 break;
8055
8056 case 6:
8057 //pivot + v flip
8058 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8059 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8060 break;
8061
8062 case 8:
8063 //vlip h
8064 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8065 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8066 break;
8067
8068 case 9:
8069 //trans + h flip
8070 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8071 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8072 break;
8073
8074 case 10:
8075 //flip H and pivot
8076 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8077 //return error cannot pivot and h flip
8078 break;
8079
8080 case 12:
8081 //vh flip
8082 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8083 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8084 break;
8085
8086 case 13:
8087 //trans + vh flip
8088 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8089 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8090 break;
8091
8092 case 14:
8093 //pivot and vh flip
8094 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8095 //return error cannot both pivot and vh flip
8096 break;
8097
8098 case 16:
8099 //lit
8100 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8101 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8102 break;
8103
8104 case 18:
8105 //pivot, lit
8106 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8107 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8108 break;
8109
8110 case 20:
8111 //lit + v flip
8112 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8113 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8114 break;
8115
8116 case 22:
8117 //Pivot, vflip, lit
8118 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8119 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8120 break;
8121
8122 case 24:
8123 //lit + h flip
8124 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8125 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8126 break;
8127
8128 case 26:
8129 //pivot + lit + hflip
8130 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8131 //return error cannot pivot, lit, and flip
8132 break;
8133
8134 case 28:
8135 //lit + vh flip
8136 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8137 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8138 break;
8139
8140 case 32: //gouraud
8141 //Probably not wort supporting.
8142 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8143 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8144 break;
8145
8146 case 0:
8147 //no effect
8148 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8149 break;
8150
8151
8152 default:
8153 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8154
8155
8156 }
8157 } //end if not rotated
8158
8159 if ( rot != 0 ) //if rotated
8160 {
8161 switch(mode)
8162 {
8163 case 1:
8164 //transparent
8165 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8166 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8167
8168 break;
8169
8170 case 2:
8171 //pivot?
8172 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8173 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8174 //Pivoting requires two more args
8175 break;
8176
8177 case 3:
8178 //pivot + trans
8179 //return an error, cannot both rotate and pivot
8180 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8181 break;
8182
8183 case 4:
8184 //flip v
8185 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8186 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8187 break;
8188
8189 case 5:
8190 //trans + v flip
8191 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8192 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8193 break;
8194
8195 case 6:
8196 //pivot + v flip
8197 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8198 //return an error, cannot both rotate and pivot
8199 break;
8200
8201 case 8:
8202 //flip h
8203 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8204 //return an error, cannot both rotate and flip H
8205 break;
8206
8207 case 9:
8208 //trans + h flip
8209 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8210 //return an error, cannot rotate and flip a trans sprite
8211 break;
8212
8213 case 10:
8214 //flip H and pivot
8215 //return error cannot pivot and h flip
8216 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8217 break;
8218
8219 case 12:
8220 //vh flip
8221 //return an error, cannot rotate and VH flip a trans sprite
8222 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8223 break;
8224
8225 case 13:
8226 //trans + vh flip
8227 //return an error, cannot rotate and VH flip a trans sprite
8228 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8229 break;
8230
8231 case 14:
8232 //pivot and vh flip
8233 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8234 //return error cannot both pivot and vh flip
8235 break;
8236
8237 case 16:
8238 //lit
8239 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8240 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8241 break;
8242
8243 case 18:
8244 //pivot, lit
8245 //return an error, cannot both rotate and pivot
8246 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8247 break;
8248
8249 case 20:
8250 //lit + vflip
8251 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8252 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8253 break;
8254
8255 case 22:
8256 //Pivot, vflip, lit
8257 //return an error, cannot both rotate and pivot
8258 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8259 break;
8260
8261 case 24:
8262 //lit + h flip
8263 //return an error, cannot both rotate and H flip
8264 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8265 break;
8266
8267 case 26:
8268 //pivot + lit + hflip
8269 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8270 //return error cannot pivot, lit, and flip
8271 break;
8272
8273 case 28:
8274 //lit + vh flip
8275 //return an error, cannot both rotate and VH flip
8276 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8277 break;
8278
8279 case 32: //gouraud
8280 //Probably not wort supporting.
8281 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8282 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8283 break;
8284
8285 case 0:
8286 //no effect.
8287 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8288 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8289 break;
8290
8291 default:
8292 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8293
8294 }
8295 }
8296 } //end if stretched and masked
8297
8298 else //stretched, not masked
8299 {
8300
8301
8302 if ( rot == 0 ) //if not rotated
8303 {
8304 switch(mode)
8305 {
8306 case 1:
8307 //transparent
8308 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8309 draw_trans_sprite(newDest, subBmp, dx, dy);
8310 break;
8311
8312
8313 case 2:
8314 //pivot?
8315 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8316 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8317 //Pivoting requires two more args
8318 break;
8319
8320 case 3:
8321 //pivot + trans
8322 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8323 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8324 break;
8325
8326 case 4:
8327 //flip v
8328 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8329 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8330 break;
8331
8332 case 5:
8333 //trans + v flip
8334 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8335 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8336 break;
8337
8338 case 6:
8339 //pivot + v flip
8340 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8341 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8342 break;
8343
8344 case 8:
8345 //vlip h
8346 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8347 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8348 break;
8349
8350 case 9:
8351 //trans + h flip
8352 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8353 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8354 break;
8355
8356 case 10:
8357 //flip H and pivot
8358 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8359 //return error cannot pivot and h flip
8360 break;
8361
8362 case 12:
8363 //vh flip
8364 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8365 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8366 break;
8367
8368 case 13:
8369 //trans + vh flip
8370 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8371 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8372 break;
8373
8374 case 14:
8375 //pivot and vh flip
8376 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8377 //return error cannot both pivot and vh flip
8378 break;
8379
8380 case 16:
8381 //lit
8382 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8383 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8384 break;
8385
8386 case 18:
8387 //pivot, lit
8388 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8389 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8390 break;
8391
8392 case 20:
8393 //lit + v flip
8394 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8395 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8396 break;
8397
8398 case 22:
8399 //Pivot, vflip, lit
8400 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8401 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8402 break;
8403
8404 case 24:
8405 //lit + h flip
8406 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8407 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8408 break;
8409
8410 case 26:
8411 //pivot + lit + hflip
8412 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8413 //return error cannot pivot, lit, and flip
8414 break;
8415
8416 case 28:
8417 //lit + vh flip
8418 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8419 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8420 break;
8421
8422 case 32: //gouraud
8423 //Probably not wort supporting.
8424 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8425 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8426 break;
8427
8428 case 0:
8429 //no effect
8430 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8431 break;
8432
8433
8434 default:
8435 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8436
8437
8438 }
8439 } //end if not rotated
8440
8441 if ( rot != 0 ) //if rotated
8442 {
8443 switch(mode)
8444 {
8445 case 1:
8446 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8447 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8448
8449 break;
8450
8451 case 2:
8452 //pivot?
8453 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8454 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8455 //Pivoting requires two more args
8456 break;
8457
8458 case 3:
8459 //pivot + trans
8460 //return an error, cannot both rotate and pivot
8461 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8462 break;
8463
8464 case 4:
8465 //flip v
8466 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8467 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8468 break;
8469
8470 case 5:
8471 //trans + v flip
8472 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8473 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8474 break;
8475
8476 case 6:
8477 //pivot + v flip
8478 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8479 //return an error, cannot both rotate and pivot
8480 break;
8481
8482 case 8:
8483 //flip h
8484 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8485 //return an error, cannot both rotate and flip H
8486 break;
8487
8488 case 9:
8489 //trans + h flip
8490 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8491 //return an error, cannot rotate and flip a trans sprite
8492 break;
8493
8494 case 10:
8495 //flip H and pivot
8496 //return error cannot pivot and h flip
8497 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8498 break;
8499
8500 case 12:
8501 //vh flip
8502 //return an error, cannot rotate and VH flip a trans sprite
8503 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8504 break;
8505
8506 case 13:
8507 //trans + vh flip
8508 //return an error, cannot rotate and VH flip a trans sprite
8509 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8510 break;
8511
8512 case 14:
8513 //pivot and vh flip
8514 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8515 //return error cannot both pivot and vh flip
8516 break;
8517
8518 case 16:
8519 //lit
8520 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8521 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8522 break;
8523
8524 case 18:
8525 //pivot, lit
8526 //return an error, cannot both rotate and pivot
8527 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8528 break;
8529
8530 case 20:
8531 //lit + vflip
8532 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8533 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8534 break;
8535
8536 case 22:
8537 //Pivot, vflip, lit
8538 //return an error, cannot both rotate and pivot
8539 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8540 break;
8541
8542 case 24:
8543 //lit + h flip
8544 //return an error, cannot both rotate and H flip
8545 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8546 break;
8547
8548 case 26:
8549 //pivot + lit + hflip
8550 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8551 //return error cannot pivot, lit, and flip
8552 break;
8553
8554 case 28:
8555 //lit + vh flip
8556 //return an error, cannot both rotate and VH flip
8557 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8558 break;
8559
8560 case 32: //gouraud
8561 //Probably not wort supporting.
8562 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8563 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8564 break;
8565
8566 case 0:
8567 //no effect.
8568 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8569 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8570 break;
8571
8572 default:
8573 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8574
8575 }
8576 }
8577
8578 } //end if stretched, but not masked
8579 }
8580 else //not stretched
8581 {
8582
8583
2/2
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
113329 if(masked) //if masked, but not stretched
8584 {
8585
8586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
113326 if ( rot == 0 ) //if not rotated
8587 {
8588
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 113326 times.
113326 switch(mode)
8589 {
8590 case 1:
8591 //transparent
8592 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8593 draw_trans_sprite(newDest, subBmp, dx, dy);
8594 break;
8595
8596
8597 case 2:
8598 //pivot?
8599 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8600 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8601 //Pivoting requires two more args
8602 break;
8603
8604 case 3:
8605 //pivot + trans
8606 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8607 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8608 break;
8609
8610 case 4:
8611 //flip v
8612 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8613 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8614 break;
8615
8616 case 5:
8617 //trans + v flip
8618 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8619 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8620 break;
8621
8622 case 6:
8623 //pivot + v flip
8624 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8625 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8626 break;
8627
8628 case 8:
8629 //vlip h
8630 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8631 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8632 break;
8633
8634 case 9:
8635 //trans + h flip
8636 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8637 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8638 break;
8639
8640 case 10:
8641 //flip H and pivot
8642 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8643 //return error cannot pivot and h flip
8644 break;
8645
8646 case 12:
8647 //vh flip
8648 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8649 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8650 break;
8651
8652 case 13:
8653 //trans + vh flip
8654 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8655 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8656 break;
8657
8658 case 14:
8659 //pivot and vh flip
8660 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8661 //return error cannot both pivot and vh flip
8662 break;
8663
8664 case 16:
8665 //lit
8666 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8667 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8668 break;
8669
8670 case 18:
8671 //pivot, lit
8672 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8673 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8674 break;
8675
8676 case 20:
8677 //lit + v flip
8678 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8679 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8680 break;
8681
8682 case 22:
8683 //Pivot, vflip, lit
8684 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8685 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8686 break;
8687
8688 case 24:
8689 //lit + h flip
8690 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8691 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8692 break;
8693
8694 case 26:
8695 //pivot + lit + hflip
8696 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8697 //return error cannot pivot, lit, and flip
8698 break;
8699
8700 case 28:
8701 //lit + vh flip
8702 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8703 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8704 break;
8705
8706 case 32: //gouraud
8707 //Probably not wort supporting.
8708 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8709 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8710 break;
8711
8712 case 0:
8713 //no effect
8714 113326 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8715 113326 break;
8716
8717
8718 default:
8719 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8720
8721
8722 }
8723 113326 } //end if not rotated
8724
8725
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( rot != 0 ) //if rotated
8726 {
8727 switch(mode)
8728 {
8729 case 1:
8730 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8731 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8732
8733 break;
8734
8735 case 2:
8736 //pivot?
8737 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8738 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8739 //Pivoting requires two more args
8740 break;
8741
8742 case 3:
8743 //pivot + trans
8744 //return an error, cannot both rotate and pivot
8745 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8746 break;
8747
8748 case 4:
8749 //flip v
8750 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8751 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8752 break;
8753
8754 case 5:
8755 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8756 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8757 break;
8758
8759 case 6:
8760 //pivot + v flip
8761 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8762 //return an error, cannot both rotate and pivot
8763 break;
8764
8765 case 8:
8766 //flip h
8767 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8768 //return an error, cannot both rotate and flip H
8769 break;
8770
8771 case 9:
8772 //trans + h flip
8773 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8774 //return an error, cannot rotate and flip a trans sprite
8775 break;
8776
8777 case 10:
8778 //flip H and pivot
8779 //return error cannot pivot and h flip
8780 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8781 break;
8782
8783 case 12:
8784 //vh flip
8785 //return an error, cannot rotate and VH flip a trans sprite
8786 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8787 break;
8788
8789 case 13:
8790 //trans + vh flip
8791 //return an error, cannot rotate and VH flip a trans sprite
8792 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8793 break;
8794
8795 case 14:
8796 //pivot and vh flip
8797 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8798 //return error cannot both pivot and vh flip
8799 break;
8800
8801 case 16:
8802 //lit
8803 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8804 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8805 break;
8806
8807 case 18:
8808 //pivot, lit
8809 //return an error, cannot both rotate and pivot
8810 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8811 break;
8812
8813 case 20:
8814 //lit + vflip
8815 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8816 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8817 break;
8818
8819 case 22:
8820 //Pivot, vflip, lit
8821 //return an error, cannot both rotate and pivot
8822 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8823 break;
8824
8825 case 24:
8826 //lit + h flip
8827 //return an error, cannot both rotate and H flip
8828 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8829 break;
8830
8831 case 26:
8832 //pivot + lit + hflip
8833 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8834 //return error cannot pivot, lit, and flip
8835 break;
8836
8837 case 28:
8838 //lit + vh flip
8839 //return an error, cannot both rotate and VH flip
8840 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8841 break;
8842
8843 case 32: //gouraud
8844 //Probably not wort supporting.
8845 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8846 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8847 break;
8848
8849 case 0:
8850 //no effect.
8851 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8852 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8853 break;
8854
8855 default:
8856 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8857
8858 }
8859 } //end rtated, masked
8860 113326 } //end if masked
8861
8862 else //not masked, and not stretched; just blit
8863 {
8864
8865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8866 {
8867
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8868 {
8869 case 1:
8870 //transparent
8871 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8872 draw_trans_sprite(newDest, subBmp, dx, dy);
8873 break;
8874
8875
8876 case 2:
8877 //pivot?
8878 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8879 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8880 //Pivoting requires two more args
8881 break;
8882
8883 case 3:
8884 //pivot + trans
8885 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8886 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8887 break;
8888
8889 case 4:
8890 //flip v
8891 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8892 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8893 break;
8894
8895 case 5:
8896 //trans + v flip
8897 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8898 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8899 break;
8900
8901 case 6:
8902 //pivot + v flip
8903 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8904 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8905 break;
8906
8907 case 8:
8908 //vlip h
8909 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8910 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8911 break;
8912
8913 case 9:
8914 //trans + h flip
8915 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8916 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8917 break;
8918
8919 case 10:
8920 //flip H and pivot
8921 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8922 //return error cannot pivot and h flip
8923 break;
8924
8925 case 12:
8926 //vh flip
8927 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8928 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8929 break;
8930
8931 case 13:
8932 //trans + vh flip
8933 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8934 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8935 break;
8936
8937 case 14:
8938 //pivot and vh flip
8939 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8940 //return error cannot both pivot and vh flip
8941 break;
8942
8943 case 16:
8944 //lit
8945 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8946 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8947 break;
8948
8949 case 18:
8950 //pivot, lit
8951 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8952 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8953 break;
8954
8955 case 20:
8956 //lit + v flip
8957 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8958 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8959 break;
8960
8961 case 22:
8962 //Pivot, vflip, lit
8963 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8964 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8965 break;
8966
8967 case 24:
8968 //lit + h flip
8969 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8970 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8971 break;
8972
8973 case 26:
8974 //pivot + lit + hflip
8975 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8976 //return error cannot pivot, lit, and flip
8977 break;
8978
8979 case 28:
8980 //lit + vh flip
8981 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8982 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8983 break;
8984
8985 case 32: //gouraud
8986 //Probably not wort supporting.
8987 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8988 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8989 break;
8990
8991 case 0:
8992 //no effect
8993 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8994 3 break;
8995
8996
8997 default:
8998 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8999
9000
9001 }
9002 3 } //end if not rotated
9003
9004
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
9005 {
9006 switch(mode)
9007 {
9008 case 1:
9009 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
9010 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9011
9012 break;
9013
9014 case 2:
9015 //pivot?
9016 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9017 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9018 //Pivoting requires two more args
9019 break;
9020
9021 case 3:
9022 //pivot + trans
9023 //return an error, cannot both rotate and pivot
9024 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9025 break;
9026
9027 case 4:
9028 //flip v
9029 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9030 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9031 break;
9032
9033 case 5:
9034 //trans + v flip
9035 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9036 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9037 break;
9038
9039 case 6:
9040 //pivot + v flip
9041 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9042 //return an error, cannot both rotate and pivot
9043 break;
9044
9045 case 8:
9046 //flip h
9047 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9048 //return an error, cannot both rotate and flip H
9049 break;
9050
9051 case 9:
9052 //trans + h flip
9053 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9054 //return an error, cannot rotate and flip a trans sprite
9055 break;
9056
9057 case 10:
9058 //flip H and pivot
9059 //return error cannot pivot and h flip
9060 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9061 break;
9062
9063 case 12:
9064 //vh flip
9065 //return an error, cannot rotate and VH flip a trans sprite
9066 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9067 break;
9068
9069 case 13:
9070 //trans + vh flip
9071 //return an error, cannot rotate and VH flip a trans sprite
9072 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9073 break;
9074
9075 case 14:
9076 //pivot and vh flip
9077 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9078 //return error cannot both pivot and vh flip
9079 break;
9080
9081 case 16:
9082 //lit
9083 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9084 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9085 break;
9086
9087 case 18:
9088 //pivot, lit
9089 //return an error, cannot both rotate and pivot
9090 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9091 break;
9092
9093 case 20:
9094 //lit + vflip
9095 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9096 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9097 break;
9098
9099 case 22:
9100 //Pivot, vflip, lit
9101 //return an error, cannot both rotate and pivot
9102 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9103 break;
9104
9105 case 24:
9106 //lit + h flip
9107 //return an error, cannot both rotate and H flip
9108 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9109 break;
9110
9111 case 26:
9112 //pivot + lit + hflip
9113 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9114 //return error cannot pivot, lit, and flip
9115 break;
9116
9117 case 28:
9118 //lit + vh flip
9119 //return an error, cannot both rotate and VH flip
9120 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9121 break;
9122
9123 case 32: //gouraud
9124 //Probably not wort supporting.
9125 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9126 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9127 break;
9128
9129 case 0:
9130 //no effect.
9131 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9132 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9133 break;
9134
9135 default:
9136 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9137
9138 }
9139 } //end if rotated
9140 } //end if not masked
9141 } //end if not stretched
9142
9143 //cleanup
9144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(subBmp)
9145 {
9146 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9147 destroy_bitmap(subBmp);
9148 }
9149
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if(newSource != destBMP)
9150 {
9151 3 destroy_bitmap(newSource);
9152 3 }
9153 113329 }
9154
9155 void do_tileblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp, char const* funcstr)
9156 {
9157 /*
9158 //sdci[1]=layer
9159 //sdci[2]=tile
9160 //sdci[3]=cset
9161 //sdci[4]=sourcex
9162 //sdci[5]=sourcey
9163 //sdci[6]=sourcew
9164 //sdci[7]=sourceh
9165 //sdci[8]=destx
9166 //sdci[9]=desty
9167 //sdci[10]=destw
9168 //sdci[11]=desth
9169 //sdci[12]=rotation/angle
9170 //scdi[13] = pivot cx
9171 //sdci[14] = pivot cy
9172 //scdi[15] = effect flags
9173
9174 // ZScript-side constant values:
9175 const int32_t BITDX_NORMAL = 0;
9176 const int32_t BITDX_TRANS = 1; //Translucent
9177 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
9178 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
9179 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
9180 //Note: Some modes cannot be combined. if a combination is not supported, an error
9181 // detailing this will be shown in allegro.log.
9182
9183 //scdi[16] = litcolour
9184 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9185 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
9186
9187 //sdci[17]=mask
9188 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
9189
9190 */
9191
9192 int32_t tile = sdci[2]/10000;
9193 int32_t cset = WRAP_CS(sdci[3]/10000);
9194
9195 int32_t sx = sdci[4]/10000;
9196 int32_t sy = sdci[5]/10000;
9197 int32_t sw = sdci[6]/10000;
9198 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
9199 int32_t sh = sdci[7]/10000;
9200 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
9201 int32_t dx = sdci[8]/10000;
9202 int32_t dy = sdci[9]/10000;
9203 int32_t dw = sdci[10]/10000;
9204 int32_t dh = sdci[11]/10000;
9205 float rot = sdci[12]/10000;
9206 int32_t cx = sdci[13]/10000;
9207 int32_t cy = sdci[14]/10000;
9208 int32_t mode = sdci[15]/10000;
9209 int32_t litcolour = sdci[16]/10000;
9210 bool masked = (sdci[17] != 0);
9211
9212 int32_t ref = 0;
9213
9214 if ( is_bmp && (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
9215 //Do we need to also check the render target and do the same thing if the
9216 //dest == -2 and the render target is not RT_SCREEN?
9217 dx += xoffset;
9218 dy += yoffset;
9219
9220 BITMAP *destbmp = nullptr;
9221 if(is_bmp)
9222 {
9223 ref = sdci[DRAWCMD_BMP_TARGET];
9224
9225 if ( ref <= 0 )
9226 {
9227 Z_scripterrlog("%s wanted to use to an invalid dest bitmap id: %d. Aborting.\n", funcstr, ref);
9228 return;
9229 }
9230 destbmp = resolveScriptingBitmap(ref);
9231 if(!destbmp)
9232 {
9233 Z_message("Warning: %s dest bitmap %d contains invalid data or is not initialized.\n", ref);
9234 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
9235 return;
9236 }
9237 }
9238 else destbmp = bmp;
9239
9240 bool stretched = (sw != dw || sh != dh);
9241
9242 BITMAP* srcbmp = create_bitmap_ex(8, sw, sh);
9243 //Draw tiles to srcbmp
9244 {
9245 clear_bitmap(srcbmp);
9246 int tx = 0, ty = 0;
9247 if(sx < 0)
9248 tx = (sx-15)/16;
9249 else if(sx > 15)
9250 tx = sx/16;
9251 if(sy < 0)
9252 ty = (sy-15)/16;
9253 else if(sy > 15)
9254 ty = sy/16;
9255
9256 int gxoff = -wrap(sx,0,15), gyoff = -wrap(sy,0,15);
9257 for(int ix = 0; ix <= sw; ix += 16)
9258 {
9259 for(int iy = 0; iy <= sh; iy += 16)
9260 {
9261 int t = tile+(tx+ix/16);
9262 int rowdiff = TILEROW(t) - TILEROW(tile);
9263 t += rowdiff * (sh/16) * TILES_PER_ROW;
9264 t += (ty+iy/16)*TILES_PER_ROW;
9265 overtile16(srcbmp, t, ix+gxoff, iy+gyoff, cset, 0);
9266 }
9267 }
9268
9269 sx = sy = 0;
9270 }
9271
9272 BITMAP* subBmp = nullptr;
9273
9274 if(rot != 0 || mode != 0)
9275 {
9276 subBmp = create_bitmap_ex(8,destbmp->w, destbmp->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
9277 clear_bitmap(subBmp);
9278
9279 if(!subBmp)
9280 {
9281 Z_scripterrlog("%s failed to create a sub-bitmap to use for %s. Aborting.\n", funcstr, "rotation");
9282 return;
9283 }
9284 }
9285
9286 //dx = dx + xoffset; //don't do this here!
9287 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
9288
9289 if(stretched)
9290 {
9291 if(masked)
9292 { //stretched and masked
9293 if ( rot == 0 )
9294 { //if not rotated
9295 switch(mode)
9296 {
9297 case 1:
9298 //transparent
9299 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9300 draw_trans_sprite(destbmp, subBmp, dx, dy);
9301 break;
9302
9303
9304 case 2:
9305 //pivot?
9306 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9307 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9308 //Pivoting requires two more args
9309 break;
9310
9311 case 3:
9312 //pivot + trans
9313 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9314 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9315 break;
9316
9317 case 4:
9318 //flip v
9319 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9320 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9321 break;
9322
9323 case 5:
9324 //trans + v flip
9325 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9326 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9327 break;
9328
9329 case 6:
9330 //pivot + v flip
9331 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9332 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9333 break;
9334
9335 case 8:
9336 //vlip h
9337 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9338 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9339 break;
9340
9341 case 9:
9342 //trans + h flip
9343 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9344 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9345 break;
9346
9347 case 10:
9348 //flip H and pivot
9349 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9350 //return error cannot pivot and h flip
9351 break;
9352
9353 case 12:
9354 //vh flip
9355 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9356 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9357 break;
9358
9359 case 13:
9360 //trans + vh flip
9361 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9362 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9363 break;
9364
9365 case 14:
9366 //pivot and vh flip
9367 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9368 //return error cannot both pivot and vh flip
9369 break;
9370
9371 case 16:
9372 //lit
9373 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9374 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9375 break;
9376
9377 case 18:
9378 //pivot, lit
9379 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9380 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9381 break;
9382
9383 case 20:
9384 //lit + v flip
9385 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9386 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9387 break;
9388
9389 case 22:
9390 //Pivot, vflip, lit
9391 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9392 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9393 break;
9394
9395 case 24:
9396 //lit + h flip
9397 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9398 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9399 break;
9400
9401 case 26:
9402 //pivot + lit + hflip
9403 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9404 //return error cannot pivot, lit, and flip
9405 break;
9406
9407 case 28:
9408 //lit + vh flip
9409 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9410 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9411 break;
9412
9413 case 32: //gouraud
9414 //Probably not wort supporting.
9415 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9416 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9417 break;
9418
9419 case 0:
9420 //no effect
9421 masked_stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9422 break;
9423
9424
9425 default:
9426 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9427
9428
9429 }
9430 } //end if not rotated
9431
9432 if ( rot != 0 ) //if rotated
9433 {
9434 switch(mode)
9435 {
9436 case 1:
9437 //transparent
9438 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9439 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9440
9441 break;
9442
9443 case 2:
9444 //pivot?
9445 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9446 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9447 //Pivoting requires two more args
9448 break;
9449
9450 case 3:
9451 //pivot + trans
9452 //return an error, cannot both rotate and pivot
9453 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9454 break;
9455
9456 case 4:
9457 //flip v
9458 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9459 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9460 break;
9461
9462 case 5:
9463 //trans + v flip
9464 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9465 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9466 break;
9467
9468 case 6:
9469 //pivot + v flip
9470 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9471 //return an error, cannot both rotate and pivot
9472 break;
9473
9474 case 8:
9475 //flip h
9476 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9477 //return an error, cannot both rotate and flip H
9478 break;
9479
9480 case 9:
9481 //trans + h flip
9482 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9483 //return an error, cannot rotate and flip a trans sprite
9484 break;
9485
9486 case 10:
9487 //flip H and pivot
9488 //return error cannot pivot and h flip
9489 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9490 break;
9491
9492 case 12:
9493 //vh flip
9494 //return an error, cannot rotate and VH flip a trans sprite
9495 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9496 break;
9497
9498 case 13:
9499 //trans + vh flip
9500 //return an error, cannot rotate and VH flip a trans sprite
9501 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9502 break;
9503
9504 case 14:
9505 //pivot and vh flip
9506 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9507 //return error cannot both pivot and vh flip
9508 break;
9509
9510 case 16:
9511 //lit
9512 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9513 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9514 break;
9515
9516 case 18:
9517 //pivot, lit
9518 //return an error, cannot both rotate and pivot
9519 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9520 break;
9521
9522 case 20:
9523 //lit + vflip
9524 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9525 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9526 break;
9527
9528 case 22:
9529 //Pivot, vflip, lit
9530 //return an error, cannot both rotate and pivot
9531 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9532 break;
9533
9534 case 24:
9535 //lit + h flip
9536 //return an error, cannot both rotate and H flip
9537 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9538 break;
9539
9540 case 26:
9541 //pivot + lit + hflip
9542 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9543 //return error cannot pivot, lit, and flip
9544 break;
9545
9546 case 28:
9547 //lit + vh flip
9548 //return an error, cannot both rotate and VH flip
9549 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9550 break;
9551
9552 case 32: //gouraud
9553 //Probably not wort supporting.
9554 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9555 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9556 break;
9557
9558 case 0:
9559 //no effect.
9560 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9561 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9562 break;
9563
9564 default:
9565 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9566
9567 }
9568 }
9569 } //end if stretched and masked
9570
9571 else //stretched, not masked
9572 {
9573
9574
9575 if ( rot == 0 ) //if not rotated
9576 {
9577 switch(mode)
9578 {
9579 case 1:
9580 //transparent
9581 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9582 draw_trans_sprite(destbmp, subBmp, dx, dy);
9583 break;
9584
9585
9586 case 2:
9587 //pivot?
9588 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9589 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9590 //Pivoting requires two more args
9591 break;
9592
9593 case 3:
9594 //pivot + trans
9595 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9596 pivot_sprite_trans(destbmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
9597 break;
9598
9599 case 4:
9600 //flip v
9601 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9602 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9603 break;
9604
9605 case 5:
9606 //trans + v flip
9607 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9608 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9609 break;
9610
9611 case 6:
9612 //pivot + v flip
9613 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9614 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9615 break;
9616
9617 case 8:
9618 //vlip h
9619 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9620 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9621 break;
9622
9623 case 9:
9624 //trans + h flip
9625 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9626 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9627 break;
9628
9629 case 10:
9630 //flip H and pivot
9631 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9632 //return error cannot pivot and h flip
9633 break;
9634
9635 case 12:
9636 //vh flip
9637 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9638 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9639 break;
9640
9641 case 13:
9642 //trans + vh flip
9643 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9644 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9645 break;
9646
9647 case 14:
9648 //pivot and vh flip
9649 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9650 //return error cannot both pivot and vh flip
9651 break;
9652
9653 case 16:
9654 //lit
9655 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9656 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9657 break;
9658
9659 case 18:
9660 //pivot, lit
9661 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9662 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9663 break;
9664
9665 case 20:
9666 //lit + v flip
9667 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9668 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9669 break;
9670
9671 case 22:
9672 //Pivot, vflip, lit
9673 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9674 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9675 break;
9676
9677 case 24:
9678 //lit + h flip
9679 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9680 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9681 break;
9682
9683 case 26:
9684 //pivot + lit + hflip
9685 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9686 //return error cannot pivot, lit, and flip
9687 break;
9688
9689 case 28:
9690 //lit + vh flip
9691 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9692 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9693 break;
9694
9695 case 32: //gouraud
9696 //Probably not wort supporting.
9697 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9698 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9699 break;
9700
9701 case 0:
9702 //no effect
9703 stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9704 break;
9705
9706
9707 default:
9708 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9709
9710
9711 }
9712 } //end if not rotated
9713
9714 if ( rot != 0 ) //if rotated
9715 {
9716 switch(mode)
9717 {
9718 case 1:
9719 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9720 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9721
9722 break;
9723
9724 case 2:
9725 //pivot?
9726 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9727 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9728 //Pivoting requires two more args
9729 break;
9730
9731 case 3:
9732 //pivot + trans
9733 //return an error, cannot both rotate and pivot
9734 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9735 break;
9736
9737 case 4:
9738 //flip v
9739 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9740 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9741 break;
9742
9743 case 5:
9744 //trans + v flip
9745 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9746 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9747 break;
9748
9749 case 6:
9750 //pivot + v flip
9751 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9752 //return an error, cannot both rotate and pivot
9753 break;
9754
9755 case 8:
9756 //flip h
9757 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9758 //return an error, cannot both rotate and flip H
9759 break;
9760
9761 case 9:
9762 //trans + h flip
9763 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9764 //return an error, cannot rotate and flip a trans sprite
9765 break;
9766
9767 case 10:
9768 //flip H and pivot
9769 //return error cannot pivot and h flip
9770 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9771 break;
9772
9773 case 12:
9774 //vh flip
9775 //return an error, cannot rotate and VH flip a trans sprite
9776 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9777 break;
9778
9779 case 13:
9780 //trans + vh flip
9781 //return an error, cannot rotate and VH flip a trans sprite
9782 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9783 break;
9784
9785 case 14:
9786 //pivot and vh flip
9787 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9788 //return error cannot both pivot and vh flip
9789 break;
9790
9791 case 16:
9792 //lit
9793 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9794 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9795 break;
9796
9797 case 18:
9798 //pivot, lit
9799 //return an error, cannot both rotate and pivot
9800 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9801 break;
9802
9803 case 20:
9804 //lit + vflip
9805 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9806 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9807 break;
9808
9809 case 22:
9810 //Pivot, vflip, lit
9811 //return an error, cannot both rotate and pivot
9812 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9813 break;
9814
9815 case 24:
9816 //lit + h flip
9817 //return an error, cannot both rotate and H flip
9818 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9819 break;
9820
9821 case 26:
9822 //pivot + lit + hflip
9823 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9824 //return error cannot pivot, lit, and flip
9825 break;
9826
9827 case 28:
9828 //lit + vh flip
9829 //return an error, cannot both rotate and VH flip
9830 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9831 break;
9832
9833 case 32: //gouraud
9834 //Probably not wort supporting.
9835 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9836 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9837 break;
9838
9839 case 0:
9840 //no effect.
9841 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9842 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9843 break;
9844
9845 default:
9846 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9847
9848 }
9849 }
9850
9851 } //end if stretched, but not masked
9852 }
9853 else //not stretched
9854 {
9855
9856 if(masked) //if masked, but not stretched
9857 {
9858
9859 if ( rot == 0 ) //if not rotated
9860 {
9861 switch(mode)
9862 {
9863 case 1:
9864 //transparent
9865 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9866 draw_trans_sprite(destbmp, subBmp, dx, dy);
9867 break;
9868
9869
9870 case 2:
9871 //pivot?
9872 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9873 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9874 //Pivoting requires two more args
9875 break;
9876
9877 case 3:
9878 //pivot + trans
9879 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9880 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9881 break;
9882
9883 case 4:
9884 //flip v
9885 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9886 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9887 break;
9888
9889 case 5:
9890 //trans + v flip
9891 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9892 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9893 break;
9894
9895 case 6:
9896 //pivot + v flip
9897 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9898 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9899 break;
9900
9901 case 8:
9902 //vlip h
9903 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9904 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9905 break;
9906
9907 case 9:
9908 //trans + h flip
9909 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9910 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9911 break;
9912
9913 case 10:
9914 //flip H and pivot
9915 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9916 //return error cannot pivot and h flip
9917 break;
9918
9919 case 12:
9920 //vh flip
9921 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9922 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9923 break;
9924
9925 case 13:
9926 //trans + vh flip
9927 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9928 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9929 break;
9930
9931 case 14:
9932 //pivot and vh flip
9933 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9934 //return error cannot both pivot and vh flip
9935 break;
9936
9937 case 16:
9938 //lit
9939 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9940 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9941 break;
9942
9943 case 18:
9944 //pivot, lit
9945 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9946 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9947 break;
9948
9949 case 20:
9950 //lit + v flip
9951 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9952 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9953 break;
9954
9955 case 22:
9956 //Pivot, vflip, lit
9957 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9958 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9959 break;
9960
9961 case 24:
9962 //lit + h flip
9963 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9964 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9965 break;
9966
9967 case 26:
9968 //pivot + lit + hflip
9969 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9970 //return error cannot pivot, lit, and flip
9971 break;
9972
9973 case 28:
9974 //lit + vh flip
9975 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9976 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9977 break;
9978
9979 case 32: //gouraud
9980 //Probably not wort supporting.
9981 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9982 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9983 break;
9984
9985 case 0:
9986 //no effect
9987 masked_blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
9988 break;
9989
9990
9991 default:
9992 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9993
9994
9995 }
9996 } //end if not rotated
9997
9998 if ( rot != 0 ) //if rotated
9999 {
10000 switch(mode)
10001 {
10002 case 1:
10003 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
10004 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10005
10006 break;
10007
10008 case 2:
10009 //pivot?
10010 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10011 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10012 //Pivoting requires two more args
10013 break;
10014
10015 case 3:
10016 //pivot + trans
10017 //return an error, cannot both rotate and pivot
10018 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10019 break;
10020
10021 case 4:
10022 //flip v
10023 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10024 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10025 break;
10026
10027 case 5:
10028 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
10029 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10030 break;
10031
10032 case 6:
10033 //pivot + v flip
10034 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10035 //return an error, cannot both rotate and pivot
10036 break;
10037
10038 case 8:
10039 //flip h
10040 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10041 //return an error, cannot both rotate and flip H
10042 break;
10043
10044 case 9:
10045 //trans + h flip
10046 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10047 //return an error, cannot rotate and flip a trans sprite
10048 break;
10049
10050 case 10:
10051 //flip H and pivot
10052 //return error cannot pivot and h flip
10053 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10054 break;
10055
10056 case 12:
10057 //vh flip
10058 //return an error, cannot rotate and VH flip a trans sprite
10059 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10060 break;
10061
10062 case 13:
10063 //trans + vh flip
10064 //return an error, cannot rotate and VH flip a trans sprite
10065 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10066 break;
10067
10068 case 14:
10069 //pivot and vh flip
10070 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10071 //return error cannot both pivot and vh flip
10072 break;
10073
10074 case 16:
10075 //lit
10076 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10077 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10078 break;
10079
10080 case 18:
10081 //pivot, lit
10082 //return an error, cannot both rotate and pivot
10083 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10084 break;
10085
10086 case 20:
10087 //lit + vflip
10088 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10089 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10090 break;
10091
10092 case 22:
10093 //Pivot, vflip, lit
10094 //return an error, cannot both rotate and pivot
10095 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10096 break;
10097
10098 case 24:
10099 //lit + h flip
10100 //return an error, cannot both rotate and H flip
10101 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10102 break;
10103
10104 case 26:
10105 //pivot + lit + hflip
10106 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10107 //return error cannot pivot, lit, and flip
10108 break;
10109
10110 case 28:
10111 //lit + vh flip
10112 //return an error, cannot both rotate and VH flip
10113 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10114 break;
10115
10116 case 32: //gouraud
10117 //Probably not wort supporting.
10118 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
10119 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10120 break;
10121
10122 case 0:
10123 //no effect.
10124 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10125 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10126 break;
10127
10128 default:
10129 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10130
10131 }
10132 } //end rtated, masked
10133 } //end if masked
10134
10135 else //not masked, and not stretched; just blit
10136 {
10137
10138 if ( rot == 0 ) //if not rotated
10139 {
10140 switch(mode)
10141 {
10142 case 1:
10143 //transparent
10144 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10145 draw_trans_sprite(destbmp, subBmp, dx, dy);
10146 break;
10147
10148
10149 case 2:
10150 //pivot?
10151 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10152 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10153 //Pivoting requires two more args
10154 break;
10155
10156 case 3:
10157 //pivot + trans
10158 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10159 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10160 break;
10161
10162 case 4:
10163 //flip v
10164 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10165 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
10166 break;
10167
10168 case 5:
10169 //trans + v flip
10170 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10171 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
10172 break;
10173
10174 case 6:
10175 //pivot + v flip
10176 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10177 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10178 break;
10179
10180 case 8:
10181 //vlip h
10182 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10183 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
10184 break;
10185
10186 case 9:
10187 //trans + h flip
10188 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10189 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
10190 break;
10191
10192 case 10:
10193 //flip H and pivot
10194 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10195 //return error cannot pivot and h flip
10196 break;
10197
10198 case 12:
10199 //vh flip
10200 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10201 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
10202 break;
10203
10204 case 13:
10205 //trans + vh flip
10206 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10207 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
10208 break;
10209
10210 case 14:
10211 //pivot and vh flip
10212 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10213 //return error cannot both pivot and vh flip
10214 break;
10215
10216 case 16:
10217 //lit
10218 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10219 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
10220 break;
10221
10222 case 18:
10223 //pivot, lit
10224 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10225 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10226 break;
10227
10228 case 20:
10229 //lit + v flip
10230 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10231 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
10232 break;
10233
10234 case 22:
10235 //Pivot, vflip, lit
10236 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10237 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10238 break;
10239
10240 case 24:
10241 //lit + h flip
10242 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10243 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
10244 break;
10245
10246 case 26:
10247 //pivot + lit + hflip
10248 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
10249 //return error cannot pivot, lit, and flip
10250 break;
10251
10252 case 28:
10253 //lit + vh flip
10254 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10255 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
10256 break;
10257
10258 case 32: //gouraud
10259 //Probably not wort supporting.
10260 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10261 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10262 break;
10263
10264 case 0:
10265 //no effect
10266 blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
10267 break;
10268
10269
10270 default:
10271 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10272
10273
10274 }
10275 } //end if not rotated
10276
10277 if ( rot != 0 ) //if rotated
10278 {
10279 switch(mode)
10280 {
10281 case 1:
10282 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
10283 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10284
10285 break;
10286
10287 case 2:
10288 //pivot?
10289 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10290 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10291 //Pivoting requires two more args
10292 break;
10293
10294 case 3:
10295 //pivot + trans
10296 //return an error, cannot both rotate and pivot
10297 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10298 break;
10299
10300 case 4:
10301 //flip v
10302 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10303 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10304 break;
10305
10306 case 5:
10307 //trans + v flip
10308 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10309 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10310 break;
10311
10312 case 6:
10313 //pivot + v flip
10314 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10315 //return an error, cannot both rotate and pivot
10316 break;
10317
10318 case 8:
10319 //flip h
10320 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10321 //return an error, cannot both rotate and flip H
10322 break;
10323
10324 case 9:
10325 //trans + h flip
10326 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10327 //return an error, cannot rotate and flip a trans sprite
10328 break;
10329
10330 case 10:
10331 //flip H and pivot
10332 //return error cannot pivot and h flip
10333 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10334 break;
10335
10336 case 12:
10337 //vh flip
10338 //return an error, cannot rotate and VH flip a trans sprite
10339 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10340 break;
10341
10342 case 13:
10343 //trans + vh flip
10344 //return an error, cannot rotate and VH flip a trans sprite
10345 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10346 break;
10347
10348 case 14:
10349 //pivot and vh flip
10350 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10351 //return error cannot both pivot and vh flip
10352 break;
10353
10354 case 16:
10355 //lit
10356 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10357 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10358 break;
10359
10360 case 18:
10361 //pivot, lit
10362 //return an error, cannot both rotate and pivot
10363 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10364 break;
10365
10366 case 20:
10367 //lit + vflip
10368 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10369 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10370 break;
10371
10372 case 22:
10373 //Pivot, vflip, lit
10374 //return an error, cannot both rotate and pivot
10375 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10376 break;
10377
10378 case 24:
10379 //lit + h flip
10380 //return an error, cannot both rotate and H flip
10381 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10382 break;
10383
10384 case 26:
10385 //pivot + lit + hflip
10386 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10387 //return error cannot pivot, lit, and flip
10388 break;
10389
10390 case 28:
10391 //lit + vh flip
10392 //return an error, cannot both rotate and VH flip
10393 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10394 break;
10395
10396 case 32: //gouraud
10397 //Probably not wort supporting.
10398 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10399 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10400 break;
10401
10402 case 0:
10403 //no effect.
10404 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10405 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10406 break;
10407
10408 default:
10409 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10410
10411 }
10412 } //end if rotated
10413 } //end if not masked
10414 } //end if not stretched
10415
10416 //cleanup
10417 if(subBmp)
10418 {
10419 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
10420 destroy_bitmap(subBmp);
10421 }
10422 destroy_bitmap(srcbmp);
10423 }
10424
10425 void do_comboblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp)
10426 {
10427 //sdci[2]: combo -> tile
10428 int cid = sdci[2]/10000;
10429 if(unsigned(cid) >= MAXCOMBOS)
10430 {
10431 Z_scripterrlog("ComboBlit tried to draw invalid combo id '%d'\n", cid);
10432 return;
10433 }
10434 sdci[2] = GET_DRAWING_COMBO(cid).tile * 10000;
10435 do_tileblit(bmp, sdci, xoffset, yoffset, is_bmp, "ComboBlit()");
10436 }
10437
10438 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10439 {
10440
10441 //sdci[1]=layer
10442 //sdci[2]=pos[12]
10443 //sdci[3]=uv[8]
10444 //sdci[4]=color[4]
10445 //sdci[5]=size[2]
10446 //sdci[6]=flip
10447 //sdci[7]=tile/combo
10448 //sdci[8]=polytype
10449 //sdci[9] = other bitmap as texture
10450 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10451 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10452 {
10453 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10454 return;
10455 }
10456 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10457 if ( refbmp == NULL ) return;
10458
10459 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10460
10461 if(!v_ptr)
10462 {
10463 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
10464 return;
10465 }
10466
10467 std::vector<int32_t> &v = *v_ptr;
10468
10469 if(v.empty())
10470 return;
10471
10472 int32_t* pos = &v[0];
10473 int32_t* uv = &v[12];
10474 int32_t* col = &v[20];
10475 int32_t* size = &v[24];
10476
10477 int32_t w = size[0]; //magic numerical constants... yuck.
10478 int32_t h = size[1];
10479 int32_t flip = (sdci[6]/10000)&3;
10480 int32_t tile = sdci[7]/10000;
10481 int32_t polytype = sdci[8]/10000;
10482 int32_t quad_render_source = sdci[9];
10483 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
10484
10485 polytype = vbound(polytype, 0, 14);
10486
10487 int32_t tex_width = w*16;
10488 int32_t tex_height = h*16;
10489
10490 bool mustDestroyBmp = false;
10491 BITMAP *tex=NULL;
10492
10493
10494 bool tex_is_bitmap = ( sdci[9] != 0 );
10495 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
10496 //Z_scripterrlog("sdci[DRAWCMD_BMP_TARGET] is %d\n", sdci[DRAWCMD_BMP_TARGET]);
10497 BITMAP *bmptexture;
10498
10499 if ( tex_is_bitmap ) bmptexture = resolveScriptingBitmap(quad_render_source);
10500
10501 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10502
10503
10504 if ( !tex_is_bitmap )
10505 {
10506 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10507
10508 if(!tex)
10509 {
10510 mustDestroyBmp = true;
10511 tex = create_bitmap_ex(8, tex_width, tex_height);
10512 clear_bitmap(tex);
10513 }
10514 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10515 {
10516 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10517 return; //non power of two error
10518 }
10519 if(tile > 0) // TILE
10520 {
10521 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10522 }
10523 else // COMBO
10524 {
10525 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
10526 const int32_t tiletodraw = combo_tile(c, 0, 0);
10527 flip = flip ^ c.flip;
10528
10529 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10530 }
10531
10532 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10533 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10534 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10535 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10536
10537 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
10538 if(mustDestroyBmp)
10539 destroy_bitmap(tex);
10540 }
10541 else
10542 {
10543
10544 if ( !bmptexture )
10545 {
10546 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
10547 tex_is_bitmap = 0;
10548 return;
10549 }
10550 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10551 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10552 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10553 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10554
10555 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10556 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10557 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10558 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10559
10560 BITMAP *foo = create_bitmap_ex(8, 256, 176);
10561
10562 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
10563 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
10564 destroy_bitmap(foo);
10565
10566 }
10567
10568
10569
10570 }
10571
10572
10573
10574 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10575 {
10576 //sdci[1]=layer
10577 //sdci[2]=pos[9]
10578 //sdci[3]=uv[6]
10579 //sdci[4]=color[3]
10580 //sdci[5]=size[2]
10581 //sdci[6]=flip
10582 //sdci[7]=tile/combo
10583 //sdci[8]=polytype
10584 //sdci[9] bitmap as texture
10585 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10586 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10587 {
10588 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10589 return;
10590 }
10591 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10592 if ( refbmp == NULL ) return;
10593
10594 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10595
10596 if(!v_ptr)
10597 {
10598 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
10599 return;
10600 }
10601
10602 std::vector<int32_t> &v = *v_ptr;
10603
10604 if(v.empty())
10605 return;
10606
10607 int32_t* pos = &v[0];
10608 int32_t* uv = &v[9];
10609 int32_t* col = &v[15];
10610 int32_t* size = &v[18];
10611
10612 int32_t w = size[0]; //magic numerical constants... yuck.
10613 int32_t h = size[1];
10614 int32_t flip = (sdci[6]/10000)&3;
10615 int32_t tile = sdci[7]/10000;
10616 int32_t polytype = sdci[8]/10000;
10617 int32_t quad_render_source = sdci[9];
10618 polytype = vbound(polytype, 0, 14);
10619
10620 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10621 {
10622 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10623 return; //non power of two error
10624 }
10625
10626 int32_t tex_width = w*16;
10627 int32_t tex_height = h*16;
10628
10629 bool mustDestroyBmp = false;
10630 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10631
10632 if(!tex)
10633 {
10634 mustDestroyBmp = true;
10635 tex = create_bitmap_ex(8, tex_width, tex_height);
10636 clear_bitmap(tex);
10637 }
10638
10639 bool tex_is_bitmap = ( sdci[9] != 0 );
10640 BITMAP *bmptexture=NULL;
10641 if ( tex_is_bitmap )
10642 {
10643 bmptexture = resolveScriptingBitmap(quad_render_source);
10644 if ( !bmptexture )
10645 {
10646 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
10647 tex_is_bitmap = 0;
10648 }
10649 }
10650
10651 if ( !tex_is_bitmap )
10652 {
10653 if(tile > 0) // TILE
10654 {
10655 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10656 }
10657 else // COMBO
10658 {
10659 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
10660 const int32_t tiletodraw = combo_tile(c, 0, 0);
10661 flip = flip ^ c.flip;
10662
10663 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10664 }
10665
10666 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10667 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10668 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10669
10670 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
10671 }
10672 else
10673 {
10674 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10675 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10676 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10677 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10678
10679 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10680 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10681 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10682
10683 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
10684
10685
10686 }
10687 if(mustDestroyBmp)
10688 destroy_bitmap(tex);
10689
10690 }
10691
10692
10693 bool is_layer_transparent(const mapscr& m, int32_t layer)
10694 {
10695 layer = vbound(layer, 0, 5);
10696 return m.layeropacity[layer] == 128;
10697 }
10698
10699 4338216 mapscr *getmapscreen(int32_t map_index, int32_t screen, int32_t layer) //returns NULL for invalid or non-existent layer
10700 {
10701 mapscr *base_scr;
10702 4338216 int32_t index = map_index*MAPSCRS+screen;
10703
10704
2/4
✓ Branch 0 taken 4338216 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4338216 times.
4338216 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
10705 return NULL;
10706
10707
2/2
✓ Branch 0 taken 3553310 times.
✓ Branch 1 taken 784906 times.
4338216 if(layer != 0)
10708 {
10709 784906 layer = layer - 1;
10710
10711 784906 base_scr=&(TheMaps[index]);
10712
10713
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_scr->layermap[layer]==0)
10714 36727 return NULL;
10715
10716 748179 index=(base_scr->layermap[layer]-1)*MAPSCRS+base_scr->layerscreen[layer];
10717
10718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
10719 return NULL;
10720 748179 }
10721
10722 4301489 return &(TheMaps[index]);
10723 4338216 }
10724
10725 636710856 static bool transparent_combo(int32_t id)
10726 {
10727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 636710856 times.
636710856 if(unsigned(id) >= MAXCOMBOS) return false;
10728 636710856 return bool(combobuf[id].animflags & AF_TRANSPARENT);
10729 636710856 }
10730
10731 191560 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
10732 {
10733
2/2
✓ Branch 0 taken 33714560 times.
✓ Branch 1 taken 191560 times.
33906120 for(int32_t i(0); i < 176; ++i)
10734 {
10735 33714560 const int32_t x2 = ((i&15)<<4) + x;
10736 33714560 const int32_t y2 = (i&0xF0) + y;
10737
10738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(transparent != transparent_combo(m.data[i]))
10739 {
10740 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
10741 }
10742 else
10743 {
10744 33714560 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
10745 }
10746 33714560 }
10747 191560 }
10748
10749 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10750 {
10751 BITMAP* square = create_bitmap_ex(8,16,16);
10752
10753 for(int32_t i(0); i < 176; ++i)
10754 {
10755 const int32_t x2 = ((i&15)<<4) + x;
10756 const int32_t y2 = (i&0xF0) + y;
10757 //Blit the palette index of the solidity value.
10758 clear_to_color(square,(combobuf[m.data[i]].walk&15));
10759 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10760 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10761 }
10762 destroy_bitmap(square);
10763 }
10764
10765 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10766 {
10767 //sdci[1]=layer
10768 //sdci[2]=map
10769 //sdci[3]=screen
10770 //sdci[4]=x
10771 //sdci[5]=y
10772 //sdci[6]=rotation
10773 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10774
10775 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10776 if ( refbmp == NULL ) return;
10777
10778 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10779
10780 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10781 int32_t screen = sdci[3]/10000;
10782 int32_t x = sdci[4]/10000;
10783 int32_t y = sdci[5]/10000;
10784 int32_t x1 = x + xoffset;
10785 int32_t y1 = y + yoffset;
10786 int32_t rotation = sdci[6]/10000;
10787 uint32_t index = (uint32_t)map_screen_index(map, screen);
10788
10789 if(index >= TheMaps.size())
10790 {
10791 al_trace("DrawScreen: invalid map or screen index. \n");
10792 return;
10793 }
10794
10795 const mapscr & m = TheMaps[index];
10796
10797
10798 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10799 if ( refbmp == NULL ) return;
10800
10801 if(rotation != 0)
10802 b = script_drawing_commands.AquireSubBitmap(256, 176);
10803
10804 //draw layer 0
10805 draw_map_solidity(b, m, x1, y1);
10806 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10807 {
10808 for(int32_t i(0); i < 6; ++i)
10809 {
10810 if(m.layermap[i] == 0) continue;
10811
10812 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10813
10814 if(layer_screen_index >= TheMaps.size())
10815 continue;
10816
10817 //draw valid layers
10818 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
10819 }
10820 }
10821
10822 if(rotation != 0) // rotate
10823 {
10824 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10825 script_drawing_commands.ReleaseSubBitmap(b);
10826 }
10827 }
10828
10829 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10830 {
10831 BITMAP* square = create_bitmap_ex(8,16,16);
10832 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10833 clear_to_color(subsquare,1);
10834
10835 for(int32_t i(0); i < 176; ++i)
10836 {
10837 const int32_t x2 = ((i&15)<<4) + x;
10838 const int32_t y2 = (i&0xF0) + y;
10839 //Blit the palette index of the solidity value.
10840 clear_bitmap(square);
10841 int32_t sol = (combobuf[m.data[i]].walk);
10842 if ( sol & 1 )
10843 {
10844 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10845 }
10846 if ( sol & 2 )
10847 {
10848 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10849 }
10850 if ( sol & 4 )
10851 {
10852 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10853 }
10854 if ( sol &8 ) {
10855 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10856 }
10857
10858 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10859 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10860 }
10861 destroy_bitmap(square);
10862 destroy_bitmap(subsquare);
10863 }
10864
10865 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10866 {
10867 //sdci[1]=layer
10868 //sdci[2]=map
10869 //sdci[3]=screen
10870 //sdci[4]=x
10871 //sdci[5]=y
10872 //sdci[6]=rotation
10873 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10874
10875 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10876 if ( refbmp == NULL ) return;
10877
10878 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10879
10880 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10881 int32_t screen = sdci[3]/10000;
10882 int32_t x = sdci[4]/10000;
10883 int32_t y = sdci[5]/10000;
10884 int32_t x1 = x + xoffset;
10885 int32_t y1 = y + yoffset;
10886 int32_t rotation = sdci[6]/10000;
10887
10888 uint32_t index = (uint32_t)map_screen_index(map, screen);
10889
10890 if(index >= TheMaps.size())
10891 {
10892 al_trace("DrawScreen: invalid map or screen index. \n");
10893 return;
10894 }
10895
10896 const mapscr & m = TheMaps[index];
10897
10898
10899 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10900 if ( refbmp == NULL ) return;
10901
10902 if(rotation != 0)
10903 b = script_drawing_commands.AquireSubBitmap(256, 176);
10904
10905 //draw layer 0
10906 draw_map_solid(b, m, x1, y1);
10907
10908 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
10909 {
10910 if(m.layermap[i] == 0) continue;
10911
10912 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10913
10914 if(layer_screen_index >= TheMaps.size())
10915 continue;
10916
10917 //draw valid layers
10918 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
10919 }
10920
10921 if(rotation != 0) // rotate
10922 {
10923 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10924 script_drawing_commands.ReleaseSubBitmap(b);
10925 }
10926 }
10927
10928 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10929 {
10930 1024 BITMAP* square = create_bitmap_ex(8,16,16);
10931
10932
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
10933 {
10934 180224 const int32_t x2 = ((i&15)<<4) + x;
10935 180224 const int32_t y2 = (i&0xF0) + y;
10936 //Blit the palette index of the solidity value.
10937 180224 clear_to_color(square,m.sflag[i]);
10938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10939 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10940 180224 }
10941 1024 destroy_bitmap(square);
10942 1024 }
10943
10944 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10945 {
10946 //sdci[1]=layer
10947 //sdci[2]=map
10948 //sdci[3]=screen
10949 //sdci[4]=x
10950 //sdci[5]=y
10951 //sdci[6]=rotation
10952 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10953
10954 1024 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10955
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10956
10957
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
1024 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10958
10959 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10960 1024 int32_t screen = sdci[3]/10000;
10961 1024 int32_t x = sdci[4]/10000;
10962 1024 int32_t y = sdci[5]/10000;
10963 1024 int32_t x1 = x + xoffset;
10964 1024 int32_t y1 = y + yoffset;
10965 1024 int32_t rotation = sdci[6]/10000;
10966
10967 1024 uint32_t index = (uint32_t)map_screen_index(map, screen);
10968
10969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
10970 {
10971 al_trace("DrawScreen: invalid map or screen index. \n");
10972 return;
10973 }
10974
10975 1024 const mapscr & m = TheMaps[index];
10976
10977
10978 1024 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10979
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10980
10981
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
10982 b = script_drawing_commands.AquireSubBitmap(256, 176);
10983
10984 //draw layer 0
10985 1024 draw_map_cflag(b, m, x1, y1);
10986
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10987 {
10988 for(int32_t i(0); i < 6; ++i)
10989 {
10990 if(m.layermap[i] == 0) continue;
10991
10992 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10993
10994 if(layer_screen_index >= TheMaps.size())
10995 continue;
10996
10997 //draw valid layers
10998 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
10999 }
11000 }
11001
11002
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
11003 {
11004 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11005 script_drawing_commands.ReleaseSubBitmap(b);
11006 }
11007 1024 }
11008
11009
11010 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11011 {
11012 BITMAP* square = create_bitmap_ex(8,16,16);
11013
11014 for(int32_t i(0); i < 176; ++i)
11015 {
11016 const int32_t x2 = ((i&15)<<4) + x;
11017 const int32_t y2 = (i&0xF0) + y;
11018 //Blit the palette index of the solidity value.
11019 clear_to_color(square,(combobuf[m.data[i]].type));
11020 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11021 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11022 }
11023 destroy_bitmap(square);
11024 }
11025
11026 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11027 {
11028 //sdci[1]=layer
11029 //sdci[2]=map
11030 //sdci[3]=screen
11031 //sdci[4]=x
11032 //sdci[5]=y
11033 //sdci[6]=rotation
11034 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11035
11036 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11037 if ( refbmp == NULL ) return;
11038
11039 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11040
11041 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11042 int32_t screen = sdci[3]/10000;
11043 int32_t x = sdci[4]/10000;
11044 int32_t y = sdci[5]/10000;
11045 int32_t x1 = x + xoffset;
11046 int32_t y1 = y + yoffset;
11047 int32_t rotation = sdci[6]/10000;
11048
11049 uint32_t index = (uint32_t)map_screen_index(map, screen);
11050
11051 if(index >= TheMaps.size())
11052 {
11053 al_trace("DrawScreen: invalid map or screen index. \n");
11054 return;
11055 }
11056
11057 const mapscr & m = TheMaps[index];
11058
11059
11060 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11061 if ( refbmp == NULL ) return;
11062
11063 if(rotation != 0)
11064 b = script_drawing_commands.AquireSubBitmap(256, 176);
11065
11066 //draw layer 0
11067 draw_map_combotype(b, m, x1, y1);
11068
11069 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11070 {
11071 for(int32_t i(0); i < 6; ++i)
11072 {
11073 if(m.layermap[i] == 0) continue;
11074
11075 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11076
11077 if(layer_screen_index >= TheMaps.size())
11078 continue;
11079
11080 //draw valid layers
11081 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
11082 }
11083 }
11084
11085 if(rotation != 0) // rotate
11086 {
11087 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11088 script_drawing_commands.ReleaseSubBitmap(b);
11089 }
11090 }
11091
11092
11093 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11094 {
11095 BITMAP* square = create_bitmap_ex(8,16,16);
11096
11097 for(int32_t i(0); i < 176; ++i)
11098 {
11099 const int32_t x2 = ((i&15)<<4) + x;
11100 const int32_t y2 = (i&0xF0) + y;
11101 //Blit the palette index of the solidity value.
11102 clear_to_color(square,(combobuf[m.data[i]].flag));
11103 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11104 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11105 }
11106 destroy_bitmap(square);
11107 }
11108
11109 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11110 {
11111 //sdci[1]=layer
11112 //sdci[2]=map
11113 //sdci[3]=screen
11114 //sdci[4]=x
11115 //sdci[5]=y
11116 //sdci[6]=rotation
11117 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11118
11119 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11120 if ( refbmp == NULL ) return;
11121
11122 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11123
11124 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11125 int32_t screen = sdci[3]/10000;
11126 int32_t x = sdci[4]/10000;
11127 int32_t y = sdci[5]/10000;
11128 int32_t x1 = x + xoffset;
11129 int32_t y1 = y + yoffset;
11130 int32_t rotation = sdci[6]/10000;
11131
11132 uint32_t index = (uint32_t)map_screen_index(map, screen);
11133
11134 if(index >= TheMaps.size())
11135 {
11136 al_trace("DrawScreen: invalid map or screen index. \n");
11137 return;
11138 }
11139
11140 const mapscr & m = TheMaps[index];
11141
11142
11143 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11144 if ( refbmp == NULL ) return;
11145
11146 if(rotation != 0)
11147 b = script_drawing_commands.AquireSubBitmap(256, 176);
11148
11149 //draw layer 0
11150 draw_map_comboiflag(b, m, x1, y1);
11151
11152 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11153 {
11154 for(int32_t i(0); i < 6; ++i)
11155 {
11156 if(m.layermap[i] == 0) continue;
11157
11158 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11159
11160 if(layer_screen_index >= TheMaps.size())
11161 continue;
11162
11163 //draw valid layers
11164 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
11165 }
11166 }
11167
11168 if(rotation != 0) // rotate
11169 {
11170 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11171 script_drawing_commands.ReleaseSubBitmap(b);
11172 }
11173 }
11174
11175 4337043 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11176 {
11177 //sdci[1]=layer
11178 //sdci[2]=map
11179 //sdci[3]=screen
11180 //sdci[4]=layer
11181 //sdci[5]=x
11182 //sdci[6]=y
11183 //sdci[7]=rotation
11184 //sdci[8]=opacity
11185
11186 4337043 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11187 4337043 int32_t screen = sdci[3]/10000;
11188 4337043 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11189 4337043 int32_t x = sdci[5]/10000;
11190 4337043 int32_t y = sdci[6]/10000;
11191 4337043 int32_t x1 = x + xoffset;
11192 4337043 int32_t y1 = y + yoffset;
11193 4337043 int32_t rotation = sdci[7]/10000;
11194 4337043 int32_t opacity = sdci[8]/10000;
11195
11196 4337043 uint32_t index = (uint32_t)map_screen_index(map, screen);
11197 4337043 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11198
11199
2/2
✓ Branch 0 taken 4300322 times.
✓ Branch 1 taken 36721 times.
4337043 if(!m) //no need to log it.
11200 36721 return;
11201
11202
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4300322 times.
4300322 if(index >= TheMaps.size())
11203 {
11204 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11205 return;
11206 }
11207
11208 4300322 const mapscr & l = *m;
11209
11210 4300322 BITMAP* b = bmp;
11211
11212
1/2
✓ Branch 0 taken 4300322 times.
✗ Branch 1 not taken.
4300322 if(rotation != 0)
11213 b = script_drawing_commands.AquireSubBitmap(256, 176);
11214
11215
11216 4300322 const int32_t maxX = isOffScreen ? 512 : 256;
11217
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 19383 times.
4300322 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11218 4300322 bool transparent = opacity <= 128;
11219
11220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4300322 times.
4300322 if(rotation != 0) // rotate
11221 {
11222 draw_mapscr(b, l, x1, y1, transparent);
11223
11224 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11225 script_drawing_commands.ReleaseSubBitmap(b);
11226 }
11227 else
11228 {
11229
2/2
✓ Branch 0 taken 756856672 times.
✓ Branch 1 taken 4300322 times.
761156994 for(int32_t i(0); i < 176; ++i)
11230 {
11231 756856672 const int32_t x2 = ((i&15)<<4) + x1;
11232 756856672 const int32_t y2 = (i&0xF0) + y1;
11233
11234
7/8
✓ Branch 0 taken 666352038 times.
✓ Branch 1 taken 90504634 times.
✓ Branch 2 taken 666352038 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611946646 times.
✓ Branch 5 taken 54405392 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 602790904 times.
756856672 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
11235 {
11236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 602790904 times.
602790904 if(opacity < 128 != transparent_combo(l.data[i]))
11237 {
11238 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
11239 }
11240 else
11241 {
11242 602790904 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
11243 }
11244 602790904 }
11245 756856672 }
11246 }
11247
11248 //putscr
11249 4337043 }
11250
11251
11252
11253 50406 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11254 {
11255 //sdci[1]=layer
11256 //sdci[2]=map
11257 //sdci[3]=screen
11258 //sdci[4]=x
11259 //sdci[5]=y
11260 //sdci[6]=rotation
11261
11262 50406 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11263 50406 int32_t screen = sdci[3]/10000;
11264 50406 int32_t x = sdci[4]/10000;
11265 50406 int32_t y = sdci[5]/10000;
11266 50406 int32_t x1 = x + xoffset;
11267 50406 int32_t y1 = y + yoffset;
11268 50406 int32_t rotation = sdci[6]/10000;
11269
11270 50406 uint32_t index = (uint32_t)map_screen_index(map, screen);
11271
11272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(index >= TheMaps.size())
11273 {
11274 al_trace("DrawScreen: invalid map or screen index. \n");
11275 return;
11276 }
11277
11278 50406 const mapscr & m = TheMaps[index];
11279
11280
11281 50406 BITMAP* b = bmp;
11282
11283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0)
11284 b = script_drawing_commands.AquireSubBitmap(256, 176);
11285
11286 //draw layer 0
11287 50406 draw_mapscr(b, m, x1, y1, false);
11288
11289
2/2
✓ Branch 0 taken 50406 times.
✓ Branch 1 taken 302436 times.
352842 for(int32_t i(0); i < 6; ++i)
11290 {
11291
2/2
✓ Branch 0 taken 137944 times.
✓ Branch 1 taken 164492 times.
302436 if(m.layermap[i] == 0) continue;
11292
11293 137944 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11294
11295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137944 times.
137944 if(layer_screen_index >= TheMaps.size())
11296 continue;
11297
11298 137944 bool trans = m.layeropacity[i] == 128;
11299
11300 //draw valid layers
11301 137944 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11302 137944 }
11303
11304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0) // rotate
11305 {
11306 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11307 script_drawing_commands.ReleaseSubBitmap(b);
11308 }
11309 50406 }
11310
11311
11312 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11313 {
11314 //sdci[1]=layer
11315 //sdci[2]=map
11316 //sdci[3]=screen
11317 //sdci[4]=layer
11318 //sdci[5]=x
11319 //sdci[6]=y
11320 //sdci[7]=rotation
11321 //[8] noclip
11322 //sdci[9]=opacity
11323 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11324
11325 1173 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11326
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
11327
11328 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11329 1173 int32_t screen = sdci[3]/10000;
11330 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11331 1173 int32_t x = sdci[5]/10000;
11332 1173 int32_t y = sdci[6]/10000;
11333 1173 int32_t rotation = sdci[7]/10000;
11334
11335 1173 byte noclip = 0;//(sdci[8]!=0);
11336 1173 int32_t opacity = sdci[8]/10000;
11337 1173 uint32_t index = (uint32_t)map_screen_index(map, screen);
11338 1173 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11339
11340
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
11341 6 return;
11342
11343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
11344 {
11345 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
11346 return;
11347 }
11348
11349 1167 const mapscr & l = *m;
11350
11351 1167 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11352
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
11353
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11354
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
11355 b = script_drawing_commands.AquireSubBitmap(256, 176);
11356
11357
11358 1167 const int32_t maxX = isOffScreen ? 512 : 256;
11359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11360 1167 bool transparent = opacity <= 128;
11361
11362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
11363 {
11364 draw_mapscr(b, l, x, y, transparent);
11365
11366 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
11367 script_drawing_commands.ReleaseSubBitmap(b);
11368 }
11369 else
11370 {
11371
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
11372 {
11373 205392 const int32_t x2 = ((i&15)<<4) + x;
11374 205392 const int32_t y2 = (i&0xF0) + y;
11375
11376 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11377 {
11378 205392 auto& c = GET_DRAWING_COMBO(l.data[i]);
11379 205392 const int32_t tile = combo_tile(c, x2, y2);
11380
11381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128 != transparent_combo(l.data[i]))
11382 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
11383 else
11384 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
11385
11386 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11387 }
11388 205392 }
11389 }
11390
11391 //putscr
11392 1173 }
11393
11394
11395
11396 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11397 {
11398 //sdci[1]=layer
11399 //sdci[2]=map
11400 //sdci[3]=screen
11401 //sdci[4]=x
11402 //sdci[5]=y
11403 //sdci[6]=rotation
11404 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11405
11406 1092 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11407
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
11408
11409
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11410
11411 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11412 1092 int32_t screen = sdci[3]/10000;
11413 1092 int32_t x = sdci[4]/10000;
11414 1092 int32_t y = sdci[5]/10000;
11415 1092 int32_t x1 = x + xoffset;
11416 1092 int32_t y1 = y + yoffset;
11417 1092 int32_t rotation = sdci[6]/10000;
11418
11419 1092 uint32_t index = (uint32_t)map_screen_index(map, screen);
11420
11421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
11422 {
11423 al_trace("DrawScreen: invalid map or screen index. \n");
11424 return;
11425 }
11426
11427 1092 const mapscr & m = TheMaps[index];
11428
11429
11430 1092 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
11432
11433
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
11434 b = script_drawing_commands.AquireSubBitmap(256, 176);
11435
11436 //draw layer 0
11437 1092 draw_mapscr(b, m, x1, y1, false);
11438
11439
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
11440 {
11441
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
11442
11443 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11444
11445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
11446 continue;
11447
11448 2118 bool trans = m.layeropacity[i] == 128;
11449
11450 //draw valid layers
11451 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11452 2118 }
11453
11454
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
11455 {
11456 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11457 script_drawing_commands.ReleaseSubBitmap(b);
11458 }
11459 1092 }
11460
11461 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11462 {
11463 //sdci[1]=layer
11464 //sdci[2]=map
11465 //sdci[3]=screen
11466 //sdci[4]=layer
11467 //sdci[5]=x
11468 //sdci[6]=y
11469 //sdci[7]=rotation
11470 //sdci[8]=bool noclip
11471 //sdci[9] == opacity
11472
11473 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11474 int32_t screen = sdci[3]/10000;
11475 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11476 int32_t x = sdci[5]/10000;
11477 int32_t y = sdci[6]/10000;
11478 int32_t x1 = x + xoffset;
11479 int32_t y1 = y + yoffset;
11480 int32_t rotation = sdci[7]/10000;
11481 byte noclip = (sdci[8]!=0);
11482 int32_t opacity = sdci[9]/10000;
11483
11484 uint32_t index = (uint32_t)map_screen_index(map, screen);
11485 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11486
11487 if(!m) //no need to log it.
11488 return;
11489
11490 if(index >= TheMaps.size())
11491 {
11492 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11493 return;
11494 }
11495
11496 const mapscr & l = *m;
11497
11498 BITMAP* b = bmp;
11499
11500 if(rotation != 0)
11501 b = script_drawing_commands.AquireSubBitmap(256, 176);
11502
11503
11504 const int32_t maxX = isOffScreen ? 512 : 256;
11505 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11506 bool transparent = opacity <= 128;
11507
11508 if(rotation != 0) // rotate
11509 {
11510 draw_map_solid(b, l, x1, y1);
11511
11512 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11513 script_drawing_commands.ReleaseSubBitmap(b);
11514 }
11515 else
11516 {
11517 BITMAP* square = create_bitmap_ex(8,16,16);
11518 BITMAP* subsquare = create_bitmap_ex(8,16,16);
11519 clear_to_color(subsquare,1);
11520 for(int32_t i(0); i < 176; ++i)
11521 {
11522 const int32_t x2 = ((i&15)<<4) + x1;
11523 const int32_t y2 = (i&0xF0) + y1;
11524
11525 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11526 {
11527 int32_t sol = (combobuf[l.data[i]].walk);
11528
11529 if ( sol & 1 )
11530 {
11531 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
11532 }
11533 if ( sol & 2 )
11534 {
11535 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
11536 }
11537 if ( sol & 4 )
11538 {
11539 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
11540 }
11541 if ( sol &8 ) {
11542 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
11543 }
11544
11545 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11546 }
11547 }
11548 destroy_bitmap(square);
11549 destroy_bitmap(subsquare);
11550 }
11551
11552 //putscr
11553 }
11554
11555 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11556 {
11557 //sdci[1]=layer
11558 //sdci[2]=map
11559 //sdci[3]=screen
11560 //sdci[4]=layer
11561 //sdci[5]=x
11562 //sdci[6]=y
11563 //sdci[7]=rotation
11564 //[8] noclip
11565 //sdci[9]=opacity
11566
11567
11568 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11569 int32_t screen = sdci[3]/10000;
11570 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11571 int32_t x = sdci[5]/10000;
11572 int32_t y = sdci[6]/10000;
11573 int32_t x1 = x + xoffset;
11574 int32_t y1 = y + yoffset;
11575 int32_t rotation = sdci[7]/10000;
11576 byte noclip = (sdci[8]!=0);
11577 int32_t opacity = sdci[9]/10000;
11578
11579 uint32_t index = (uint32_t)map_screen_index(map, screen);
11580 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11581
11582 if(!m) //no need to log it.
11583 return;
11584
11585 if(index >= TheMaps.size())
11586 {
11587 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11588 return;
11589 }
11590
11591 const mapscr & l = *m;
11592
11593 BITMAP* b = bmp;
11594
11595 if(rotation != 0)
11596 b = script_drawing_commands.AquireSubBitmap(256, 176);
11597
11598
11599 const int32_t maxX = isOffScreen ? 512 : 256;
11600 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11601 bool transparent = opacity <= 128;
11602
11603 if(rotation != 0) // rotate
11604 {
11605 draw_map_solidity(b, l, x1, y1);
11606
11607 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11608 script_drawing_commands.ReleaseSubBitmap(b);
11609 }
11610 else
11611 {
11612 BITMAP* square = create_bitmap_ex(8,16,16);
11613 for(int32_t i(0); i < 176; ++i)
11614 {
11615 const int32_t x2 = ((i&15)<<4) + x1;
11616 const int32_t y2 = (i&0xF0) + y1;
11617
11618 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11619 {
11620 clear_to_color(square,(combobuf[l.data[i]].walk&15));
11621 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11622 }
11623 }
11624 destroy_bitmap(square);
11625 }
11626
11627 //putscr
11628 }
11629
11630 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11631 {
11632 //sdci[1]=layer
11633 //sdci[2]=map
11634 //sdci[3]=screen
11635 //sdci[4]=layer
11636 //sdci[5]=x
11637 //sdci[6]=y
11638 //sdci[7]=rotation
11639 //[8] noclip
11640 //sdci[9]=opacity
11641
11642
11643 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11644 int32_t screen = sdci[3]/10000;
11645 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11646 int32_t x = sdci[5]/10000;
11647 int32_t y = sdci[6]/10000;
11648 int32_t x1 = x + xoffset;
11649 int32_t y1 = y + yoffset;
11650 int32_t rotation = sdci[7]/10000;
11651
11652 byte noclip = (sdci[8]!=0);
11653 int32_t opacity = sdci[9]/10000;
11654
11655 uint32_t index = (uint32_t)map_screen_index(map, screen);
11656 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11657
11658 if(!m) //no need to log it.
11659 return;
11660
11661 if(index >= TheMaps.size())
11662 {
11663 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11664 return;
11665 }
11666
11667 const mapscr & l = *m;
11668
11669 BITMAP* b = bmp;
11670
11671 if(rotation != 0)
11672 b = script_drawing_commands.AquireSubBitmap(256, 176);
11673
11674
11675 const int32_t maxX = isOffScreen ? 512 : 256;
11676 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11677 bool transparent = opacity <= 128;
11678
11679 if(rotation != 0) // rotate
11680 {
11681 draw_map_cflag(b, l, x1, y1);
11682
11683 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11684 script_drawing_commands.ReleaseSubBitmap(b);
11685 }
11686 else
11687 {
11688 BITMAP* square = create_bitmap_ex(8,16,16);
11689 for(int32_t i(0); i < 176; ++i)
11690 {
11691 const int32_t x2 = ((i&15)<<4) + x1;
11692 const int32_t y2 = (i&0xF0) + y1;
11693
11694 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11695 {
11696 clear_to_color(square,l.sflag[i]);
11697 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11698 }
11699 }
11700 destroy_bitmap(square);
11701 }
11702
11703 //putscr
11704 }
11705
11706 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11707 {
11708 //sdci[1]=layer
11709 //sdci[2]=map
11710 //sdci[3]=screen
11711 //sdci[4]=layer
11712 //sdci[5]=x
11713 //sdci[6]=y
11714 //sdci[7]=rotation
11715 //[8] noclip
11716 //sdci[9]=opacity
11717
11718 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11719 int32_t screen = sdci[3]/10000;
11720 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11721 int32_t x = sdci[5]/10000;
11722 int32_t y = sdci[6]/10000;
11723 int32_t x1 = x + xoffset;
11724 int32_t y1 = y + yoffset;
11725 int32_t rotation = sdci[7]/10000;
11726
11727 byte noclip = (sdci[8]!=0);
11728 int32_t opacity = sdci[9]/10000;
11729 uint32_t index = (uint32_t)map_screen_index(map, screen);
11730 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11731
11732 if(!m) //no need to log it.
11733 return;
11734
11735 if(index >= TheMaps.size())
11736 {
11737 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11738 return;
11739 }
11740
11741 const mapscr & l = *m;
11742
11743 BITMAP* b = bmp;
11744
11745 if(rotation != 0)
11746 b = script_drawing_commands.AquireSubBitmap(256, 176);
11747
11748
11749 const int32_t maxX = isOffScreen ? 512 : 256;
11750 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11751 bool transparent = opacity <= 128;
11752
11753 if(rotation != 0) // rotate
11754 {
11755 draw_map_combotype(b, l, x1, y1);
11756
11757 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11758 script_drawing_commands.ReleaseSubBitmap(b);
11759 }
11760 else
11761 {
11762 BITMAP* square = create_bitmap_ex(8,16,16);
11763 for(int32_t i(0); i < 176; ++i)
11764 {
11765 const int32_t x2 = ((i&15)<<4) + x1;
11766 const int32_t y2 = (i&0xF0) + y1;
11767
11768 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11769 {
11770 clear_to_color(square,(combobuf[l.data[i]].type));
11771 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11772 }
11773 }
11774 destroy_bitmap(square);
11775 }
11776
11777 //putscr
11778 }
11779
11780 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11781 {
11782 //sdci[1]=layer
11783 //sdci[2]=map
11784 //sdci[3]=screen
11785 //sdci[4]=layer
11786 //sdci[5]=x
11787 //sdci[6]=y
11788 //sdci[7]=rotation
11789 //[8] noclip
11790 //sdci[9]=opacity
11791
11792 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11793 int32_t screen = sdci[3]/10000;
11794 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11795 int32_t x = sdci[5]/10000;
11796 int32_t y = sdci[6]/10000;
11797 int32_t x1 = x + xoffset;
11798 int32_t y1 = y + yoffset;
11799 int32_t rotation = sdci[7]/10000;
11800 byte noclip = (sdci[8]!=0);
11801 int32_t opacity = sdci[9]/10000;
11802
11803 uint32_t index = (uint32_t)map_screen_index(map, screen);
11804 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11805
11806 if(!m) //no need to log it.
11807 return;
11808
11809 if(index >= TheMaps.size())
11810 {
11811 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11812 return;
11813 }
11814
11815 const mapscr & l = *m;
11816
11817 BITMAP* b = bmp;
11818
11819 if(rotation != 0)
11820 b = script_drawing_commands.AquireSubBitmap(256, 176);
11821
11822
11823 const int32_t maxX = isOffScreen ? 512 : 256;
11824 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11825 bool transparent = opacity <= 128;
11826
11827 if(rotation != 0) // rotate
11828 {
11829 draw_map_comboiflag(b, l, x1, y1);
11830
11831 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11832 script_drawing_commands.ReleaseSubBitmap(b);
11833 }
11834 else
11835 {
11836 BITMAP* square = create_bitmap_ex(8,16,16);
11837 for(int32_t i(0); i < 176; ++i)
11838 {
11839 const int32_t x2 = ((i&15)<<4) + x1;
11840 const int32_t y2 = (i&0xF0) + y1;
11841
11842 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11843 {
11844 clear_to_color(square,(combobuf[l.data[i]].flag));
11845 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11846 }
11847 }
11848 destroy_bitmap(square);
11849 }
11850
11851 //putscr
11852 }
11853
11854
11855
11856 /////////////////////////////////////////////////////////
11857 // do primitives
11858 ////////////////////////////////////////////////////////
11859
11860 // Draw commands can vary in terms of the origin/coordinate system to draw as. This
11861 // is controlled via `DrawOrigin`. Previous to `DrawOrigin`, this always drew
11862 // relative to the playing field (except for offscreen bitmaps).
11863 401433545 void do_primitives(BITMAP *targetBitmap, int32_t type)
11864 {
11865 401433545 do_primitives(targetBitmap, type, 0, playing_field_offset);
11866 401433545 }
11867
11868 402636033 void do_primitives(BITMAP *targetBitmap, int32_t type, int32_t xoff, int32_t yoff)
11869 {
11870 402636033 color_map = &trans_table2;
11871
11872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 402636033 times.
402636033 if(type > 7)
11873 return;
11874
3/4
✓ Branch 0 taken 128058181 times.
✓ Branch 1 taken 274577852 times.
✓ Branch 2 taken 128058181 times.
✗ Branch 3 not taken.
402636033 if(type >= 0 && origin_scr->hidescriptlayers & (1<<type))
11875 return; //Script draws hidden for this layer
11876
2/2
✓ Branch 0 taken 3402281 times.
✓ Branch 1 taken 399233752 times.
402636033 if(!script_drawing_commands.is_dirty(type))
11877 399233752 return; //No draws to this layer
11878 //--script_drawing_commands[][] reference--
11879 //[][0]: type
11880 //[][1-16]: defined by type
11881 //...
11882 //[][DRAWCMD_BMP_TARGET]: bitmap pointer
11883 //[][DRAWCMD_CURRENT_TARGET]: current render target at time command is queued? unused?
11884
11885 3402281 const int32_t type_mul_10000 = type * 10000;
11886 3402281 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
11887 3402281 FFCore.numscriptdraws = numDrawCommandsToProcess;
11888
11889
2/2
✓ Branch 0 taken 300653819 times.
✓ Branch 1 taken 3402281 times.
304056100 for (int i = 0; i < numDrawCommandsToProcess; i++)
11890 {
11891 300653819 auto& command = script_drawing_commands[i];
11892 300653819 int32_t *sdci = &script_drawing_commands[i][0];
11893
11894
2/2
✓ Branch 0 taken 200198473 times.
✓ Branch 1 taken 100455346 times.
300653819 if (sdci[1] != type_mul_10000)
11895 200198473 continue;
11896
11897 100455346 DrawOrigin draw_origin = command.draw_origin;
11898
11899 // get the correct render target, if set via Screen->SetRenderTarget
11900 // Note: This is a deprecated feature.
11901 100455346 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[DRAWCMD_CURRENT_TARGET]);
11902 bool isTargetOffScreenBmp;
11903
11904
2/2
✓ Branch 0 taken 6431906 times.
✓ Branch 1 taken 94023440 times.
100455346 if(!bmp)
11905 {
11906 94023440 bmp = targetBitmap;
11907 94023440 isTargetOffScreenBmp = false;
11908 94023440 }
11909 else
11910 {
11911 // Render target was set to a internal bitmap (but not the screen bitmap).
11912 6431906 isTargetOffScreenBmp = true;
11913 6431906 draw_origin = DrawOrigin::Screen;
11914 }
11915
11916 100455346 current_target_bmp = bmp;
11917
11918 int xoffset, yoffset;
11919
1/2
✓ Branch 0 taken 100455346 times.
✗ Branch 1 not taken.
100455346 if (auto r = get_draw_origin_offset(draw_origin, command.draw_origin_target, xoff, yoff))
11920 {
11921 100455346 std::tie(xoffset, yoffset) = *r;
11922 100455346 }
11923 else
11924 {
11925 continue;
11926 }
11927
11928 100455346 secondary_draw_origin_xoff = 0;
11929 100455346 secondary_draw_origin_yoff = 0;
11930
2/2
✓ Branch 0 taken 100454986 times.
✓ Branch 1 taken 360 times.
100455346 if (command.secondary_draw_origin != DrawOrigin::Default)
11931 {
11932
1/2
✓ Branch 0 taken 360 times.
✗ Branch 1 not taken.
360 if (auto r = get_draw_origin_offset(command.secondary_draw_origin, command.secondary_draw_origin_target, xoff, yoff))
11933 {
11934 360 std::tie(secondary_draw_origin_xoff, secondary_draw_origin_yoff) = *r;
11935 360 }
11936 else
11937 {
11938 continue;
11939 }
11940 360 }
11941
11942
40/88
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 2499888 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1170321 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1850 times.
✓ Branch 7 taken 2351475 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 404879 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1576950 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2745108 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5303765 times.
✓ Branch 19 taken 22453186 times.
✓ Branch 20 taken 963845 times.
✓ Branch 21 taken 165084 times.
✓ Branch 22 taken 1598985 times.
✓ Branch 23 taken 163717 times.
✓ Branch 24 taken 9266 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1080 times.
✓ Branch 29 taken 933060 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 4337043 times.
✓ Branch 32 taken 50406 times.
✓ Branch 33 taken 7971 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 148823 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 502 times.
✓ Branch 38 taken 144 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 80910 times.
✓ Branch 41 taken 59816 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 824 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 168443 times.
✓ Branch 46 taken 32636464 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 865 times.
✓ Branch 50 taken 45504 times.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 1173 times.
✓ Branch 58 taken 1092 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1024 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 265749 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 113329 times.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 325125 times.
✓ Branch 74 taken 3150 times.
✓ Branch 75 taken 34653 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✓ Branch 81 taken 19821648 times.
✗ Branch 82 not taken.
✓ Branch 83 taken 7323 times.
✗ Branch 84 not taken.
✓ Branch 85 taken 906 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
100455346 switch(sdci[0])
11943 {
11944 case RECTR:
11945 {
11946 2499888 do_rectr(bmp, sdci, xoffset, yoffset);
11947 }
11948 2499888 break;
11949 case FRAMER:
11950 {
11951 do_framer(bmp, sdci, xoffset, yoffset);
11952 }
11953 break;
11954
11955
11956 case CIRCLER:
11957 {
11958 1170321 do_circler(bmp, sdci, xoffset, yoffset);
11959 }
11960 1170321 break;
11961
11962 case ARCR:
11963 {
11964 do_arcr(bmp, sdci, xoffset, yoffset);
11965 }
11966 break;
11967
11968 case ELLIPSER:
11969 {
11970 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
11971 }
11972 1850 break;
11973
11974 case LINER:
11975 {
11976 2351475 do_liner(bmp, sdci, xoffset, yoffset);
11977 }
11978 2351475 break;
11979
11980 case SPLINER:
11981 {
11982 do_spliner(bmp, sdci, xoffset, yoffset);
11983 }
11984 break;
11985
11986 case PUTPIXELR:
11987 {
11988 404879 do_putpixelr(bmp, sdci, xoffset, yoffset);
11989 }
11990 404879 break;
11991 case PIXELARRAYR:
11992 {
11993 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
11994 }
11995 break;
11996
11997 case TILEARRAYR:
11998 {
11999 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
12000 }
12001 break;
12002
12003 case LINESARRAY:
12004 {
12005 do_linesr(bmp, i, sdci, xoffset, yoffset);
12006 }
12007 break;
12008
12009 case COMBOARRAYR:
12010 {
12011 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
12012 }
12013 break;
12014
12015
12016
12017 case DRAWTILER:
12018 {
12019 1576950 do_drawtiler(bmp, sdci, xoffset, yoffset);
12020 }
12021 1576950 break;
12022
12023 case DRAWTILECLOAKEDR:
12024 {
12025 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
12026 }
12027 break;
12028
12029 case DRAWCOMBOR:
12030 {
12031 2745108 do_drawcombor(bmp, sdci, xoffset, yoffset);
12032 }
12033 2745108 break;
12034
12035 case DRAWCOMBOCLOAKEDR:
12036 {
12037 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
12038 }
12039 break;
12040
12041 case FASTTILER:
12042 {
12043 5303765 do_fasttiler(bmp, sdci, xoffset, yoffset);
12044 }
12045 5303765 break;
12046
12047 case FASTCOMBOR:
12048 {
12049 22453186 do_fastcombor(bmp, sdci, xoffset, yoffset);
12050 }
12051 22453186 break;
12052
12053 case DRAWCHARR:
12054 {
12055 963845 do_drawcharr(bmp, sdci, xoffset, yoffset);
12056 }
12057 963845 break;
12058
12059 case DRAWINTR:
12060 {
12061 165084 do_drawintr(bmp, sdci, xoffset, yoffset);
12062 }
12063 165084 break;
12064
12065 case DRAWSTRINGR:
12066 {
12067 1598985 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
12068 }
12069 1598985 break;
12070
12071 case DRAWSTRINGR2:
12072 {
12073 163717 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
12074 }
12075 163717 break;
12076
12077 case QUADR:
12078 {
12079 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
12080 }
12081 9266 break;
12082
12083 case QUAD3DR:
12084 {
12085 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
12086 }
12087 break;
12088
12089 case TRIANGLER:
12090 {
12091 do_drawtriangler(bmp, sdci, xoffset, yoffset);
12092 }
12093 break;
12094
12095 case TRIANGLE3DR:
12096 {
12097 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
12098 }
12099 break;
12100
12101 case POLYGONR:
12102 {
12103 1080 do_polygonr(bmp, i, sdci, xoffset, yoffset);
12104 }
12105 1080 break;
12106
12107
12108 case BITMAPR:
12109 {
12110 933060 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
12111 }
12112 933060 break;
12113
12114 case BITMAPEXR:
12115 {
12116 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
12117 }
12118 break;
12119
12120 case DRAWLAYERR:
12121 {
12122 4337043 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12123 }
12124 4337043 break;
12125
12126 case DRAWSCREENR:
12127 {
12128 50406 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12129 }
12130 50406 break;
12131
12132 7971 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
12133 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
12134 148823 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
12135 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
12136 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
12137 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
12138 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
12139 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
12140 59816 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
12141 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
12142 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
12143 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
12144 168443 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
12145 32636464 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
12146 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
12147 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
12148 865 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
12149 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
12150 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
12151 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
12152
12153 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
12154 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
12155 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
12156 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
12157 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12158 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12159 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12160 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12161 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12162 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12163 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12164 265749 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
12165 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
12166 113329 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
12167 case TILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, false, "TileBlit()"); break;
12168 case COMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, false); break;
12169 case BMPTILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, true, "TileBlit()"); break;
12170 case BMPCOMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, true); break;
12171 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
12172 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
12173 325125 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
12174 3150 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
12175 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
12176
12177 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12178 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12179 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12180 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12181 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12182 19821648 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
12183 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
12184 7323 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
12185 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
12186 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
12187 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
12188
12189 // The following are special cases, in that the target bitmap is fixed (darkscr_bmp).
12190
12191 case DRAWLIGHT_CONE:
12192 {
12193 int32_t cx = sdci[2]/10000 + xoffset;
12194 int32_t cy = sdci[3]/10000 + yoffset;
12195 int32_t dir = sdci[4]/10000;
12196 int32_t length = sdci[5];
12197 int32_t transp_rad = sdci[6];
12198 int32_t dith_rad = sdci[7];
12199 int32_t dith_type = sdci[8];
12200 int32_t dith_arg = sdci[9];
12201
12202 if(length >= 0) length /= 10000;
12203 else length = game->get_light_rad()*2;
12204 if(!length) break;
12205 if(dir < 0) break;
12206 else dir = NORMAL_DIR(dir);
12207 if(transp_rad >= 0) transp_rad /= 10000;
12208 if(dith_rad >= 0) dith_rad /= 10000;
12209 if(dith_type >= 0) dith_type /= 10000;
12210 if(dith_arg >= 0) dith_arg /= 10000;
12211
12212 // Undo the inherit offset applied within the function. xoffset/yoffset handles for us here.
12213 cx += viewport.x;
12214 cy += viewport.y;
12215
12216 doDarkroomCone(cx,cy,length,dir,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12217 }
12218 break;
12219
12220 case DRAWLIGHT_CIRCLE:
12221 case DRAWLIGHT_SQUARE:
12222 {
12223 int32_t cx = sdci[2]/10000 + xoffset;
12224 int32_t cy = sdci[3]/10000 + yoffset;
12225 int32_t radius = sdci[4];
12226 int32_t transp_rad = sdci[5];
12227 int32_t dith_rad = sdci[6];
12228 int32_t dith_type = sdci[7];
12229 int32_t dith_arg = sdci[8];
12230
12231 if(radius >= 0) radius /= 10000;
12232 else radius = game->get_light_rad();
12233 if(!radius) break;
12234 if(transp_rad >= 0) transp_rad /= 10000;
12235 if(dith_rad >= 0) dith_rad /= 10000;
12236 if(dith_type >= 0) dith_type /= 10000;
12237 if(dith_arg >= 0) dith_arg /= 10000;
12238
12239 // Undo the inherit offset applied within the function. xoffset/yoffset handles for us here.
12240 cx += viewport.x;
12241 cy += viewport.y;
12242
12243 if (sdci[0] == DRAWLIGHT_CIRCLE)
12244 doDarkroomCircle(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12245 else
12246 doDarkroomSquare(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12247 }
12248 break;
12249 }
12250 100455346 }
12251
12252
12253 3402281 color_map=&trans_table;
12254 402636033 }
12255
12256 16236028 void CScriptDrawingCommands::Clear()
12257 {
12258 16236028 scb.update();
12259 16236028 dirty_layers.clear();
12260
2/2
✓ Branch 0 taken 11503189 times.
✓ Branch 1 taken 4732839 times.
16236028 if(commands.empty())
12261 11503189 return;
12262
12263 //only clear what was used.
12264 4732839 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12265 4732839 count = 0;
12266
12267 4732839 draw_container.Clear();
12268 16236028 }
12269 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
12270 {
12271 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
12272 if(commands.empty())
12273 return ret;
12274 ret->push_commands(this, false);
12275
12276 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12277 count = 0;
12278
12279 draw_container.Clear();
12280 return ret;
12281 }
12282 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
12283 {
12284 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
12285 count += other->count;
12286 if(del) delete other;
12287 }
12288
12289 150311 void do_script_draws(BITMAP *targetBitmap, mapscr* scr, int32_t xoff, int32_t yoff, bool hideLayer7)
12290 {
12291
2/2
✓ Branch 0 taken 149317 times.
✓ Branch 1 taken 994 times.
150311 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, xoff, yoff);
12292
2/2
✓ Branch 0 taken 148493 times.
✓ Branch 1 taken 1818 times.
150311 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, xoff, yoff);
12293 150311 do_primitives(targetBitmap, 0, xoff, yoff);
12294 150311 do_primitives(targetBitmap, 1, xoff, yoff);
12295
2/2
✓ Branch 0 taken 994 times.
✓ Branch 1 taken 149317 times.
150311 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, xoff, yoff);
12296
2/2
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 148493 times.
150311 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, xoff, yoff);
12297 150311 do_primitives(targetBitmap, 4, xoff, yoff);
12298 150311 do_primitives(targetBitmap, 5, xoff, yoff);
12299 150311 do_primitives(targetBitmap, 6, xoff, yoff);
12300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 150311 times.
150311 if(!hideLayer7) do_primitives(targetBitmap, 7, xoff, yoff);
12301 150311 }
12302